MCPcopy
hub / github.com/cli/cli / deleteRun

Function deleteRun

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

Source from the content-addressed store, hash-verified

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