NewCmdView creates the gh issue artifact view command.
(f *cmdutil.Factory, runF func(*ViewOptions) error)
| 39 | |
| 40 | // NewCmdView creates the gh issue artifact view command. |
| 41 | func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { |
| 42 | opts := &ViewOptions{ |
| 43 | IO: f.IOStreams, |
| 44 | Browser: f.Browser, |
| 45 | Now: time.Now, |
| 46 | } |
| 47 | |
| 48 | cmd := &cobra.Command{ |
| 49 | Use: "view {<issue> <artifact-number> | <artifact-url>}", |
| 50 | Short: "View an issue artifact (preview)", |
| 51 | Long: heredoc.Docf(` |
| 52 | Display an issue artifact's name, type, authors, content, and edit history. A |
| 53 | link shows its URL. |
| 54 | |
| 55 | Name the artifact by its issue and number, or by its URL. %[1]s<issue>%[1]s is an |
| 56 | issue number or URL. |
| 57 | |
| 58 | By default, the current version is shown. Use %[1]s--version%[1]s to show an earlier |
| 59 | version from the edit history. |
| 60 | |
| 61 | With %[1]s--web%[1]s, open a document's page on GitHub, or a link's URL. |
| 62 | `, "`"), |
| 63 | Example: heredoc.Doc(` |
| 64 | # View artifact 2 on issue 142 |
| 65 | $ gh issue artifact view 142 2 |
| 66 | |
| 67 | # View an earlier version |
| 68 | $ gh issue artifact view 142 2 --version 5 |
| 69 | |
| 70 | # View an artifact by its URL |
| 71 | $ gh issue artifact view https://github.com/monalisa/monas-cafe/issues/142/artifacts/3 |
| 72 | |
| 73 | # Open a link artifact in the browser |
| 74 | $ gh issue artifact view 142 3 --web |
| 75 | |
| 76 | # Print an artifact's body |
| 77 | $ gh issue artifact view 142 2 --json body --jq .body |
| 78 | `), |
| 79 | Args: cmdutil.RangeArgs(1, 2, shared.MissingArtifactMessage), |
| 80 | RunE: func(cmd *cobra.Command, args []string) error { |
| 81 | versionSet := cmd.Flags().Changed("version") |
| 82 | if err := cmdutil.MutuallyExclusive("specify only one of `--version` or `--json`", versionSet, opts.Exporter != nil); err != nil { |
| 83 | return err |
| 84 | } |
| 85 | if err := cmdutil.MutuallyExclusive("specify only one of `--version` or `--web`", versionSet, opts.WebMode); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | if versionSet && opts.Version < 1 { |
| 89 | return cmdutil.FlagErrorf("invalid version: %v", opts.Version) |
| 90 | } |
| 91 | |
| 92 | var err error |
| 93 | opts.IssueNumber, opts.BaseRepo, opts.ArtifactNumber, err = shared.ParseArtifactArg(args, f.BaseRepo) |
| 94 | if err != nil { |
| 95 | return cmdutil.FlagErrorWrap(err) |
| 96 | } |
| 97 | opts.Client = shared.ClientFunc(f) |
| 98 |