| 66 | } |
| 67 | |
| 68 | func NewCmdEditItem(f *cmdutil.Factory, runF func(config editItemConfig) error) *cobra.Command { |
| 69 | opts := editItemOpts{} |
| 70 | editItemCmd := &cobra.Command{ |
| 71 | Use: "item-edit", |
| 72 | Short: "Edit an item in a project", |
| 73 | Long: heredoc.Docf(` |
| 74 | Edit either a draft issue or a project item. Both usages require the ID of the item to edit. |
| 75 | |
| 76 | For non-draft issues, the ID of the project is also required, and only a single field value can be updated per invocation. |
| 77 | |
| 78 | Remove project item field value using %[1]s--clear%[1]s flag. |
| 79 | `, "`"), |
| 80 | Example: heredoc.Doc(` |
| 81 | # Edit an item's text field value |
| 82 | $ gh project item-edit --id <item-id> --field-id <field-id> --project-id <project-id> --text "new text" |
| 83 | |
| 84 | # Clear an item's field value |
| 85 | $ gh project item-edit --id <item-id> --field-id <field-id> --project-id <project-id> --clear |
| 86 | `), |
| 87 | RunE: func(cmd *cobra.Command, args []string) error { |
| 88 | opts.numberChanged = cmd.Flags().Changed("number") |
| 89 | opts.titleChanged = cmd.Flags().Changed("title") |
| 90 | opts.bodyChanged = cmd.Flags().Changed("body") |
| 91 | if err := cmdutil.MutuallyExclusive( |
| 92 | "only one of `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` may be used", |
| 93 | opts.text != "", |
| 94 | opts.numberChanged, |
| 95 | opts.date != "", |
| 96 | opts.singleSelectOptionID != "", |
| 97 | opts.iterationID != "", |
| 98 | ); err != nil { |
| 99 | return err |
| 100 | } |
| 101 | |
| 102 | if err := cmdutil.MutuallyExclusive( |
| 103 | "cannot use `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` in conjunction with `--clear`", |
| 104 | opts.text != "" || opts.numberChanged || opts.date != "" || opts.singleSelectOptionID != "" || opts.iterationID != "", |
| 105 | opts.clear, |
| 106 | ); err != nil { |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | client, err := client.New(f) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | config := editItemConfig{ |
| 116 | io: f.IOStreams, |
| 117 | client: client, |
| 118 | opts: opts, |
| 119 | } |
| 120 | |
| 121 | // allow testing of the command without actually running it |
| 122 | if runF != nil { |
| 123 | return runF(config) |
| 124 | } |
| 125 | return runEditItem(config) |