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