NewCmdEdit creates the gh issue artifact edit command.
(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*EditOptions) error)
| 48 | |
| 49 | // NewCmdEdit creates the gh issue artifact edit command. |
| 50 | func NewCmdEdit(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*EditOptions) error) *cobra.Command { |
| 51 | opts := &EditOptions{ |
| 52 | IO: f.IOStreams, |
| 53 | HttpClient: f.HttpClient, |
| 54 | } |
| 55 | |
| 56 | cmd := &cobra.Command{ |
| 57 | Use: "edit {<issue> <artifact-number> | <artifact-url>}", |
| 58 | Short: "Edit an issue artifact (preview)", |
| 59 | Long: heredoc.Docf(` |
| 60 | Rename an issue artifact or replace its content. The type never changes, so a |
| 61 | link's new content must be an http(s) URL or a %[1]s.url%[1]s Internet Shortcut file. |
| 62 | |
| 63 | Name the artifact by its issue and number, or by its URL. %[1]s<issue>%[1]s is an |
| 64 | issue number or URL. |
| 65 | |
| 66 | With only %[1]s--attach%[1]s, the attachments are appended to the current content. |
| 67 | |
| 68 | With %[1]s--restore-version%[1]s, an earlier version's name and content are saved as a |
| 69 | new version. %[1]sgh issue artifact view%[1]s shows the edit history. |
| 70 | `, "`"), |
| 71 | Example: heredoc.Doc(` |
| 72 | # Rename an artifact |
| 73 | $ gh issue artifact edit 142 2 --name 'OAuth callback plan v2' |
| 74 | |
| 75 | # Replace a document's content with a file |
| 76 | $ gh issue artifact edit 142 2 --body-file 2-OAuth-callback-plan.md |
| 77 | |
| 78 | # Point a link at a new URL |
| 79 | $ gh issue artifact edit 142 3 --body https://github.com/monalisa/monas-cafe/wiki/OAuth-runbook-v2 |
| 80 | |
| 81 | # Append an image to a document |
| 82 | $ gh issue artifact edit 142 2 --attach ./signin-flow.png |
| 83 | |
| 84 | # Restore an earlier version |
| 85 | $ gh issue artifact edit 142 2 --restore-version 5 |
| 86 | `), |
| 87 | Args: cmdutil.RangeArgs(1, 2, shared.MissingArtifactMessage), |
| 88 | RunE: func(cmd *cobra.Command, args []string) error { |
| 89 | var err error |
| 90 | opts.IssueNumber, opts.BaseRepo, opts.ArtifactNumber, err = shared.ParseArtifactArg(args, f.BaseRepo) |
| 91 | if err != nil { |
| 92 | return cmdutil.FlagErrorWrap(err) |
| 93 | } |
| 94 | |
| 95 | // An empty --body-file names no file, as in gh issue edit. |
| 96 | editing := opts.Name != nil || opts.Body != nil || opts.BodyFile != "" || opts.AttachFlag.Changed() |
| 97 | restoring := cmd.Flags().Changed("restore-version") |
| 98 | if restoring && editing { |
| 99 | return cmdutil.FlagErrorf("the `--restore-version` flag is not supported with `--name`, `--body`, `--body-file`, or `--attach`") |
| 100 | } |
| 101 | if err := cmdutil.MutuallyExclusive("specify only one of `--body` or `--body-file`", opts.Body != nil, opts.BodyFile != ""); err != nil { |
| 102 | return err |
| 103 | } |
| 104 | switch { |
| 105 | case restoring && opts.RestoreVersion < 1: |
| 106 | return cmdutil.FlagErrorf("invalid version: %v", opts.RestoreVersion) |
| 107 | case !restoring && !editing: |