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

Function NewCmdView

pkg/cmd/pr/view/view.go:40–87  ·  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 if err := cmdutil.MutuallyExclusive("specify only one of --comments or --json",
61 opts.Comments, opts.Exporter != nil); err != nil {
62 return err
63 }
64
65 opts.Finder = shared.NewFinder(f)
66
67 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
68 return cmdutil.FlagErrorf("argument required when using the --repo flag")
69 }
70
71 if len(args) > 0 {
72 opts.SelectorArg = args[0]
73 }
74
75 if runF != nil {
76 return runF(opts)
77 }
78 return viewRun(opts)
79 },
80 }
81
82 cmd.Flags().BoolVarP(&opts.BrowserMode, "web", "w", false, "Open a pull request in the browser")
83 cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View pull request comments")
84 cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.PullRequestFields)
85
86 return cmd
87}
88
89var defaultFields = []string{
90 "url", "number", "title", "state", "body", "author", "autoMergeRequest",

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