| 40 | } |
| 41 | |
| 42 | func 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 | 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 | issueNumber, baseRepo, err := issueShared.ParseIssueFromArg(args[0]) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | // If the args provided the base repo then use that directly. |
| 71 | if baseRepo, present := baseRepo.Value(); present { |
| 72 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 73 | return baseRepo, nil |
| 74 | } |
| 75 | } else { |
| 76 | // support `-R, --repo` override |
| 77 | opts.BaseRepo = f.BaseRepo |
| 78 | } |
| 79 | |
| 80 | opts.IssueNumber = issueNumber |
| 81 | |
| 82 | if runF != nil { |
| 83 | return runF(opts) |
| 84 | } |
| 85 | return viewRun(opts) |
| 86 | }, |
| 87 | } |
| 88 | |
| 89 | cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open an issue in the browser") |
| 90 | cmd.Flags().BoolVarP(&opts.Comments, "comments", "c", false, "View issue comments") |
| 91 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, api.IssueFields) |
| 92 | |
| 93 | return cmd |
| 94 | } |
| 95 | |
| 96 | var defaultFields = []string{ |
| 97 | "number", "url", "state", "createdAt", "title", "body", "author", "milestone", |