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

Function NewCmdView

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

Source from the content-addressed store, hash-verified

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

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