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

Function deleteRun

pkg/cmd/gist/delete/delete.go:79–143  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

77}
78
79func deleteRun(opts *DeleteOptions) error {
80 client, err := opts.HttpClient()
81 if err != nil {
82 return err
83 }
84
85 cfg, err := opts.Config()
86 if err != nil {
87 return err
88 }
89
90 host, _ := cfg.Authentication().DefaultHost()
91
92 gistID := opts.Selector
93 if strings.Contains(gistID, "/") {
94 id, err := shared.GistIDFromURL(gistID)
95 if err != nil {
96 return err
97 }
98 gistID = id
99 }
100
101 cs := opts.IO.ColorScheme()
102 var gist *shared.Gist
103 if gistID == "" {
104 gist, err = shared.PromptGists(opts.Prompter, client, host, cs)
105 } else {
106 gist, err = shared.GetGist(client, host, gistID)
107 }
108 if err != nil {
109 return err
110 }
111 if gist.ID == "" {
112 fmt.Fprintln(opts.IO.Out, "No gists found.")
113 return nil
114 }
115
116 if !opts.Confirmed {
117 confirmed, err := opts.Prompter.Confirm(fmt.Sprintf("Delete %q gist?", gist.Filename()), false)
118 if err != nil {
119 return err
120 }
121 if !confirmed {
122 return cmdutil.CancelError
123 }
124 }
125
126 apiClient := api.NewClientFromHTTP(client)
127 if err := deleteGist(apiClient, host, gist.ID); err != nil {
128 if errors.Is(err, shared.NotFoundErr) {
129 return fmt.Errorf("unable to delete gist %q: either the gist is not found or it is not owned by you", gist.Filename())
130 }
131 return err
132 }
133
134 if opts.IO.IsStdoutTTY() {
135 cs := opts.IO.ColorScheme()
136 fmt.Fprintf(opts.IO.Out,

Callers 2

NewCmdDeleteFunction · 0.70
Test_deleteRunFunction · 0.70

Calls 15

FilenameMethod · 0.95
GistIDFromURLFunction · 0.92
PromptGistsFunction · 0.92
GetGistFunction · 0.92
NewClientFromHTTPFunction · 0.92
deleteGistFunction · 0.85
ContainsMethod · 0.80
ColorSchemeMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconMethod · 0.80
ConfigMethod · 0.65
DefaultHostMethod · 0.65

Tested by 1

Test_deleteRunFunction · 0.56