| 26 | } |
| 27 | |
| 28 | func newCmdDelete(f *cmdutil.Factory, runF func(*deleteOptions) error) *cobra.Command { |
| 29 | opts := deleteOptions{ |
| 30 | HttpClient: f.HttpClient, |
| 31 | IO: f.IOStreams, |
| 32 | Prompter: f.Prompter, |
| 33 | } |
| 34 | |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "delete <name>", |
| 37 | Short: "Delete a label from a repository", |
| 38 | Args: cmdutil.ExactArgs(1, "cannot delete label: name argument required"), |
| 39 | RunE: func(c *cobra.Command, args []string) error { |
| 40 | // support `-R, --repo` override |
| 41 | opts.BaseRepo = f.BaseRepo |
| 42 | opts.Name = args[0] |
| 43 | |
| 44 | if !opts.IO.CanPrompt() && !opts.Confirmed { |
| 45 | return cmdutil.FlagErrorf("--yes required when not running interactively") |
| 46 | } |
| 47 | |
| 48 | if runF != nil { |
| 49 | return runF(&opts) |
| 50 | } |
| 51 | return deleteRun(&opts) |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Confirm deletion without prompting") |
| 56 | _ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead") |
| 57 | cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting") |
| 58 | |
| 59 | return cmd |
| 60 | } |
| 61 | |
| 62 | func deleteRun(opts *deleteOptions) error { |
| 63 | httpClient, err := opts.HttpClient() |