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

Function NewCmdDelete

pkg/cmd/issue/artifact/delete/delete.go:37–85  ·  view source on GitHub ↗

NewCmdDelete creates the gh issue artifact delete command.

(f *cmdutil.Factory, runF func(*DeleteOptions) error)

Source from the content-addressed store, hash-verified

35
36// NewCmdDelete creates the gh issue artifact delete command.
37func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
38 opts := &DeleteOptions{
39 IO: f.IOStreams,
40 Prompter: f.Prompter,
41 }
42
43 cmd := &cobra.Command{
44 Use: "delete {<issue> <artifact-number>... | <artifact-url>...}",
45 Short: "Delete issue artifacts (preview)",
46 Long: heredoc.Docf(`
47 Delete artifacts from an issue. A deleted artifact can't be restored.
48
49 Name artifacts by their issue and numbers, or by their URLs, which must all be
50 on one issue. %[1]s<issue>%[1]s is an issue number or URL.
51
52 In a terminal, deletion requires confirmation. %[1]s--yes%[1]s skips the prompt and is
53 required when prompting is unavailable.
54 `, "`"),
55 Example: heredoc.Doc(`
56 # Delete artifact 2 from issue 142
57 $ gh issue artifact delete 142 2
58
59 # Delete two artifacts without a prompt
60 $ gh issue artifact delete 142 2 5 --yes
61 `),
62 Args: cmdutil.MinimumArgs(1, shared.MissingArtifactMessage),
63 RunE: func(cmd *cobra.Command, args []string) error {
64 var err error
65 opts.IssueNumber, opts.BaseRepo, opts.ArtifactNumbers, err = shared.ParseArtifactArgs(args, f.BaseRepo, false)
66 if err != nil {
67 return cmdutil.FlagErrorWrap(err)
68 }
69
70 if !opts.IO.CanPrompt() && !opts.Confirmed {
71 return cmdutil.FlagErrorf("--yes required when not running interactively")
72 }
73 opts.Client = shared.ClientFunc(f)
74
75 if runF != nil {
76 return runF(opts)
77 }
78 return deleteRun(opts)
79 },
80 }
81
82 cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting")
83
84 return cmd
85}
86
87// lookup is what gh learned about one artifact number before deleting it.
88type lookup struct {

Callers 1

TestNewCmdDeleteFunction · 0.70

Calls 7

MinimumArgsFunction · 0.92
ParseArtifactArgsFunction · 0.92
FlagErrorWrapFunction · 0.92
FlagErrorfFunction · 0.92
ClientFuncFunction · 0.92
CanPromptMethod · 0.80
deleteRunFunction · 0.70

Tested by 1

TestNewCmdDeleteFunction · 0.56