MCPcopy Create free account
hub / github.com/cli/cli / NewCmdDelete

Function NewCmdDelete

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

Source from the content-addressed store, hash-verified

32}
33
34func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
35 opts := &DeleteOptions{
36 IO: f.IOStreams,
37 HttpClient: f.HttpClient,
38 BaseRepo: f.BaseRepo,
39 Prompter: f.Prompter,
40 }
41
42 cmd := &cobra.Command{
43 Use: "delete [<repository>]",
44 Short: "Delete a repository",
45 Long: heredoc.Docf(`
46 Delete a GitHub repository.
47
48 With no argument, deletes the current repository. Otherwise, deletes the specified repository.
49
50 For safety, when no repository argument is provided, the %[1]s--yes%[1]s flag is ignored
51 and you will be prompted for confirmation. To delete the current repository non-interactively,
52 specify it explicitly (e.g., %[1]sgh repo delete owner/repo --yes%[1]s).
53
54 Deleting a private repository that is not itself a fork also deletes its forks, including
55 forks you may not be able to see. If it has forks, you will be asked to confirm deleting
56 them, even with %[1]s--yes%[1]s. Pass %[1]s--accept-cascading-deletion-of-private-forks%[1]s
57 to skip that prompt. When not running interactively, it is required along with %[1]s--yes%[1]s.
58 Like %[1]s--yes%[1]s, it is ignored when no repository argument is provided.
59
60 Deletion requires authorization with the %[1]sdelete_repo%[1]s scope.
61 To authorize, run %[1]sgh auth refresh -s delete_repo%[1]s
62 `, "`"),
63 Args: cobra.MaximumNArgs(1),
64 RunE: func(cmd *cobra.Command, args []string) error {
65 if len(args) > 0 {
66 opts.RepoArg = args[0]
67 }
68
69 // Ignore confirmation flags when no argument provided to prevent accidental deletion
70 if len(args) == 0 && (opts.Confirmed || opts.AcceptCascadingDeletionOfPrivateForks) {
71 if !opts.IO.CanPrompt() {
72 return cmdutil.FlagErrorf("cannot non-interactively delete current repository. Please specify a repository or run interactively")
73 }
74 if opts.Confirmed {
75 _, _ = fmt.Fprintln(opts.IO.ErrOut, "Warning: `--yes` is ignored since no repository was specified")
76 opts.Confirmed = false
77 }
78 if opts.AcceptCascadingDeletionOfPrivateForks {
79 _, _ = fmt.Fprintln(opts.IO.ErrOut, "Warning: `--accept-cascading-deletion-of-private-forks` is ignored since no repository was specified")
80 opts.AcceptCascadingDeletionOfPrivateForks = false
81 }
82 }
83
84 if !opts.IO.CanPrompt() && !opts.Confirmed {
85 return cmdutil.FlagErrorf("--yes required when not running interactively")
86 }
87
88 if runF != nil {
89 return runF(opts)
90 }
91

Callers 1

TestNewCmdDeleteFunction · 0.70

Calls 3

FlagErrorfFunction · 0.92
CanPromptMethod · 0.80
deleteRunFunction · 0.70

Tested by 1

TestNewCmdDeleteFunction · 0.56