MCPcopy Index your code
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

pkg/cmd/pr/view/view.go:40–82  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ViewOptions) error)

Source from the content-addressed store, hash-verified

38}
39
40func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
41 opts := &ViewOptions{
42 IO: f.IOStreams,
43 Browser: f.Browser,
44 Now: time.Now,
45 }
46
47 cmd := &cobra.Command{
48 Use: "view [<number> | <url> | <branch>]",
49 Short: "View a pull request",
50 Long: heredoc.Docf(`
51 Display the title, body, and other information about a pull request.
52
53 Without an argument, the pull request that belongs to the current branch
54 is displayed.
55
56 With %[1]s--web%[1]s flag, open the pull request in a web browser instead.
57 `, "`"),
58 Args: cobra.MaximumNArgs(1),
59 RunE: func(cmd *cobra.Command, args []string) error {
60 opts.Finder = shared.NewFinder(f)
61
62 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
63 return cmdutil.FlagErrorf("argument required when using the --repo flag")
64 }
65
66 if len(args) > 0 {
67 opts.SelectorArg = args[0]
68 }
69
70 if runF != nil {
71 return runF(opts)
72 }
73 return viewRun(opts)
74 },
75 }
76
77 cmd.Flags().BoolVarP(&opts.BrowserMode, "web", "w", false, "Open a pull request in the browser")
78 cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View pull request comments")
79 cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.PullRequestFields)
80
81 return cmd
82}
83
84var defaultFields = []string{
85 "url", "number", "title", "state", "body", "author", "autoMergeRequest",

Callers 2

Test_NewCmdViewFunction · 0.70
runCommandFunction · 0.70

Calls 4

NewFinderFunction · 0.92
FlagErrorfFunction · 0.92
AddJSONFlagsFunction · 0.92
viewRunFunction · 0.70

Tested by 2

Test_NewCmdViewFunction · 0.56
runCommandFunction · 0.56