MCPcopy Index your code
hub / github.com/cli/cli / NewCmdDelete

Function NewCmdDelete

pkg/cmd/repo/delete/delete.go:31–85  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*DeleteOptions) error)

Source from the content-addressed store, hash-verified

29}
30
31func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
32 opts := &DeleteOptions{
33 IO: f.IOStreams,
34 HttpClient: f.HttpClient,
35 BaseRepo: f.BaseRepo,
36 Prompter: f.Prompter,
37 }
38
39 cmd := &cobra.Command{
40 Use: "delete [<repository>]",
41 Short: "Delete a repository",
42 Long: heredoc.Docf(`
43 Delete a GitHub repository.
44
45 With no argument, deletes the current repository. Otherwise, deletes the specified repository.
46
47 For safety, when no repository argument is provided, the %[1]s--yes%[1]s flag is ignored
48 and you will be prompted for confirmation. To delete the current repository non-interactively,
49 specify it explicitly (e.g., %[1]sgh repo delete owner/repo --yes%[1]s).
50
51 Deletion requires authorization with the %[1]sdelete_repo%[1]s scope.
52 To authorize, run %[1]sgh auth refresh -s delete_repo%[1]s
53 `, "`"),
54 Args: cobra.MaximumNArgs(1),
55 RunE: func(cmd *cobra.Command, args []string) error {
56 if len(args) > 0 {
57 opts.RepoArg = args[0]
58 }
59
60 // Ignore --yes when no argument provided to prevent accidental deletion
61 if len(args) == 0 && opts.Confirmed {
62 if !opts.IO.CanPrompt() {
63 return cmdutil.FlagErrorf("cannot non-interactively delete current repository. Please specify a repository or run interactively")
64 }
65 _, _ = fmt.Fprintln(opts.IO.ErrOut, "Warning: `--yes` is ignored since no repository was specified")
66 opts.Confirmed = false
67 }
68
69 if !opts.IO.CanPrompt() && !opts.Confirmed {
70 return cmdutil.FlagErrorf("--yes required when not running interactively")
71 }
72
73 if runF != nil {
74 return runF(opts)
75 }
76
77 return deleteRun(opts)
78 },
79 }
80
81 cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Confirm deletion without prompting")
82 _ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead")
83 cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting")
84 return cmd
85}
86
87func deleteRun(opts *DeleteOptions) error {
88 httpClient, err := opts.HttpClient()

Callers 1

TestNewCmdDeleteFunction · 0.70

Calls 3

FlagErrorfFunction · 0.92
CanPromptMethod · 0.80
deleteRunFunction · 0.70

Tested by 1

TestNewCmdDeleteFunction · 0.56