| 34 | } |
| 35 | |
| 36 | func NewCmdDeleteItem(f *cmdutil.Factory, runF func(config deleteItemConfig) error) *cobra.Command { |
| 37 | opts := deleteItemOpts{} |
| 38 | deleteItemCmd := &cobra.Command{ |
| 39 | Short: "Delete an item from a project by ID", |
| 40 | Use: "item-delete [<number>]", |
| 41 | Example: heredoc.Doc(` |
| 42 | # Delete an item in the current user's project "1" |
| 43 | $ gh project item-delete 1 --owner "@me" --id <item-id> |
| 44 | `), |
| 45 | Args: cobra.MaximumNArgs(1), |
| 46 | RunE: func(cmd *cobra.Command, args []string) error { |
| 47 | client, err := client.New(f) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | if len(args) == 1 { |
| 53 | num, err := strconv.ParseInt(args[0], 10, 32) |
| 54 | if err != nil { |
| 55 | return cmdutil.FlagErrorf("invalid number: %v", args[0]) |
| 56 | } |
| 57 | opts.number = int32(num) |
| 58 | } |
| 59 | |
| 60 | config := deleteItemConfig{ |
| 61 | client: client, |
| 62 | opts: opts, |
| 63 | io: f.IOStreams, |
| 64 | } |
| 65 | |
| 66 | // allow testing of the command without actually running it |
| 67 | if runF != nil { |
| 68 | return runF(config) |
| 69 | } |
| 70 | return runDeleteItem(config) |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | deleteItemCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.") |
| 75 | deleteItemCmd.Flags().StringVar(&opts.itemID, "id", "", "ID of the item to delete") |
| 76 | cmdutil.AddFormatFlags(deleteItemCmd, &opts.exporter) |
| 77 | |
| 78 | _ = deleteItemCmd.MarkFlagRequired("id") |
| 79 | |
| 80 | return deleteItemCmd |
| 81 | } |
| 82 | |
| 83 | func runDeleteItem(config deleteItemConfig) error { |
| 84 | canPrompt := config.io.CanPrompt() |