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

Function NewCmdDelete

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

Source from the content-addressed store, hash-verified

28}
29
30func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
31 opts := DeleteOptions{
32 IO: f.IOStreams,
33 Config: f.Config,
34 HttpClient: f.HttpClient,
35 Prompter: f.Prompter,
36 }
37
38 cmd := &cobra.Command{
39 Use: "delete {<id> | <url>}",
40 Short: "Delete a gist",
41 Long: heredoc.Docf(`
42 Delete a GitHub gist.
43
44 To delete a gist interactively, use %[1]sgh gist delete%[1]s with no arguments.
45
46 To delete a gist non-interactively, supply the gist id or url.
47 `, "`"),
48 Example: heredoc.Doc(`
49 # Delete a gist interactively
50 $ gh gist delete
51
52 # Delete a gist non-interactively
53 $ gh gist delete 1234
54 `),
55 Args: cobra.MaximumNArgs(1),
56 RunE: func(c *cobra.Command, args []string) error {
57 if !opts.IO.CanPrompt() && !opts.Confirmed {
58 return cmdutil.FlagErrorf("--yes required when not running interactively")
59 }
60
61 if !opts.IO.CanPrompt() && len(args) == 0 {
62 return cmdutil.FlagErrorf("id or url argument required in non-interactive mode")
63 }
64
65 if len(args) == 1 {
66 opts.Selector = args[0]
67 }
68
69 if runF != nil {
70 return runF(&opts)
71 }
72 return deleteRun(&opts)
73 },
74 }
75 cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting")
76 return cmd
77}
78
79func deleteRun(opts *DeleteOptions) error {
80 client, 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