| 23 | } |
| 24 | |
| 25 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 26 | opts := &DeleteOptions{ |
| 27 | HttpClient: f.HttpClient, |
| 28 | Config: f.Config, |
| 29 | IO: f.IOStreams, |
| 30 | Prompter: f.Prompter, |
| 31 | } |
| 32 | |
| 33 | cmd := &cobra.Command{ |
| 34 | Use: "delete <key-id>", |
| 35 | Short: "Delete a GPG key from your GitHub account", |
| 36 | Args: cmdutil.ExactArgs(1, "cannot delete: key id required"), |
| 37 | RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | opts.KeyID = args[0] |
| 39 | |
| 40 | if !opts.IO.CanPrompt() && !opts.Confirmed { |
| 41 | return cmdutil.FlagErrorf("--yes required when not running interactively") |
| 42 | } |
| 43 | |
| 44 | if runF != nil { |
| 45 | return runF(opts) |
| 46 | } |
| 47 | return deleteRun(opts) |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Skip the confirmation prompt") |
| 52 | _ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead") |
| 53 | cmd.Flags().BoolVarP(&opts.Confirmed, "yes", "y", false, "Skip the confirmation prompt") |
| 54 | return cmd |
| 55 | } |
| 56 | |
| 57 | func deleteRun(opts *DeleteOptions) error { |
| 58 | httpClient, err := opts.HttpClient() |