| 22 | } |
| 23 | |
| 24 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 25 | opts := &DeleteOptions{ |
| 26 | HttpClient: f.HttpClient, |
| 27 | Config: f.Config, |
| 28 | IO: f.IOStreams, |
| 29 | Prompter: f.Prompter, |
| 30 | } |
| 31 | |
| 32 | cmd := &cobra.Command{ |
| 33 | Use: "delete <id>", |
| 34 | Short: "Delete an SSH key from your GitHub account", |
| 35 | Args: cmdutil.ExactArgs(1, "cannot delete: key id required"), |
| 36 | RunE: func(cmd *cobra.Command, args []string) error { |
| 37 | opts.KeyID = args[0] |
| 38 | |
| 39 | if !opts.IO.CanPrompt() && !opts.Confirmed { |
| 40 | return cmdutil.FlagErrorf("--yes required when not running interactively") |
| 41 | } |
| 42 | |
| 43 | if runF != nil { |
| 44 | return runF(opts) |
| 45 | } |
| 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 | |
| 55 | return cmd |
| 56 | } |
| 57 | |
| 58 | func deleteRun(opts *DeleteOptions) error { |
| 59 | httpClient, err := opts.HttpClient() |