MCPcopy
hub / github.com/cli/cli / NewCmdView

Function NewCmdView

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

Source from the content-addressed store, hash-verified

40}
41
42func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
43 opts := &ViewOptions{
44 IO: f.IOStreams,
45 HttpClient: f.HttpClient,
46 Browser: f.Browser,
47 Now: time.Now,
48 }
49
50 cmd := &cobra.Command{
51 Use: "view {<number> | <url>}",
52 Short: "View an issue",
53 Long: heredoc.Docf(`
54 Display the title, body, and other information about an issue.
55
56 With %[1]s--web%[1]s flag, open the issue in a web browser instead.
57 `, "`"),
58 Args: cobra.ExactArgs(1),
59 RunE: func(cmd *cobra.Command, args []string) error {
60 issueNumber, baseRepo, err := issueShared.ParseIssueFromArg(args[0])
61 if err != nil {
62 return err
63 }
64
65 // If the args provided the base repo then use that directly.
66 if baseRepo, present := baseRepo.Value(); present {
67 opts.BaseRepo = func() (ghrepo.Interface, error) {
68 return baseRepo, nil
69 }
70 } else {
71 // support `-R, --repo` override
72 opts.BaseRepo = f.BaseRepo
73 }
74
75 opts.IssueNumber = issueNumber
76
77 if runF != nil {
78 return runF(opts)
79 }
80 return viewRun(opts)
81 },
82 }
83
84 cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open an issue in the browser")
85 cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View issue comments")
86 cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.IssueFields)
87
88 return cmd
89}
90
91var defaultFields = []string{
92 "number", "url", "state", "createdAt", "title", "body", "author", "milestone",

Callers 1

runCommandFunction · 0.70

Calls 3

AddJSONFlagsFunction · 0.92
ValueMethod · 0.80
viewRunFunction · 0.70

Tested by 1

runCommandFunction · 0.56