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

Function NewCmdView

pkg/cmd/issue/view/view.go:42–97  ·  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 When %[1]s--comments%[1]s is used, terminal output includes the issue details and comments.
57 When output is piped or redirected, only the comments are printed.
58
59 With %[1]s--web%[1]s flag, open the issue in a web browser instead.
60 `, "`"),
61 Args: cobra.ExactArgs(1),
62 RunE: func(cmd *cobra.Command, args []string) error {
63 if err := cmdutil.MutuallyExclusive("specify only one of --comments or --json",
64 opts.Comments, opts.Exporter != nil); err != nil {
65 return err
66 }
67
68 issueNumber, baseRepo, err := issueShared.ParseIssueFromArg(args[0])
69 if err != nil {
70 return err
71 }
72
73 // If the args provided the base repo then use that directly.
74 if baseRepo, present := baseRepo.Value(); present {
75 opts.BaseRepo = func() (ghrepo.Interface, error) {
76 return baseRepo, nil
77 }
78 } else {
79 // support `-R, --repo` override
80 opts.BaseRepo = f.BaseRepo
81 }
82
83 opts.IssueNumber = issueNumber
84
85 if runF != nil {
86 return runF(opts)
87 }
88 return viewRun(opts)
89 },
90 }
91
92 cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open an issue in the browser")
93 cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View issue comments")
94 cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.IssueFields)
95
96 return cmd
97}
98
99var defaultFields = []string{

Callers 2

TestNewCmdViewFunction · 0.70
runCommandFunction · 0.70

Calls 4

MutuallyExclusiveFunction · 0.92
AddJSONFlagsFunction · 0.92
ValueMethod · 0.80
viewRunFunction · 0.70

Tested by 2

TestNewCmdViewFunction · 0.56
runCommandFunction · 0.56