MCPcopy
hub / github.com/cli/cli / NewCmdDelete

Function NewCmdDelete

pkg/cmd/ssh-key/delete/delete.go:24–56  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*DeleteOptions) error)

Source from the content-addressed store, hash-verified

22}
23
24func 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
58func deleteRun(opts *DeleteOptions) error {
59 httpClient, err := opts.HttpClient()

Callers 1

TestNewCmdDeleteFunction · 0.70

Calls 4

ExactArgsFunction · 0.92
FlagErrorfFunction · 0.92
CanPromptMethod · 0.80
deleteRunFunction · 0.70

Tested by 1

TestNewCmdDeleteFunction · 0.56