MCPcopy Create free account
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

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

Source from the content-addressed store, hash-verified

43}
44
45func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
46 opts := &ViewOptions{
47 IO: f.IOStreams,
48 HttpClient: f.HttpClient,
49 Browser: f.Browser,
50 Now: time.Now,
51 InvokingAgent: f.InvokingAgent,
52 }
53
54 cmd := &cobra.Command{
55 Use: "view [<number> | <url> | <branch>]",
56 Short: "View a pull request",
57 Long: heredoc.Docf(`
58 Display the title, body, and other information about a pull request.
59
60 Without an argument, the pull request that belongs to the current branch
61 is displayed.
62
63 When %[1]s--comments%[1]s is used, terminal output includes the pull request details, comments,
64 and reviews. When output is piped or redirected, only comments and reviews are printed.
65
66 With %[1]s--web%[1]s flag, open the pull request in a web browser instead.
67
68 This command shows a snapshot. To wait for a pull request on %[1]sgithub.com%[1]s to be reviewed, merged, or closed,
69 use %[1]sgh event listen%[1]s instead of polling.
70 Changes made before the listener starts are not reported, so read the pull request once it is listening.
71 `, "`"),
72 Args: cobra.MaximumNArgs(1),
73 RunE: func(cmd *cobra.Command, args []string) error {
74 if err := cmdutil.MutuallyExclusive("specify only one of --comments or --json",
75 opts.Comments, opts.Exporter != nil); err != nil {
76 return err
77 }
78
79 opts.Finder = shared.NewFinder(f)
80
81 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
82 return cmdutil.FlagErrorf("argument required when using the --repo flag")
83 }
84
85 if len(args) > 0 {
86 opts.SelectorArg = args[0]
87 }
88
89 if runF != nil {
90 return runF(opts)
91 }
92 return viewRun(opts)
93 },
94 }
95
96 cmd.Flags().BoolVarP(&opts.BrowserMode, "web", "w", false, "Open a pull request in the browser")
97 cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View pull request comments")
98 cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.PullRequestFields)
99
100 return cmd
101}
102

Callers 2

Test_NewCmdViewFunction · 0.70
runCommandFunction · 0.70

Calls 5

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

Tested by 2

Test_NewCmdViewFunction · 0.56
runCommandFunction · 0.56