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

Function deleteCaches

pkg/cmd/cache/delete/delete.go:159–201  ·  view source on GitHub ↗
(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface, toDelete []string)

Source from the content-addressed store, hash-verified

157}
158
159func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface, toDelete []string) error {
160 cs := opts.IO.ColorScheme()
161 repoName := ghrepo.FullName(repo)
162 opts.IO.StartProgressIndicator()
163
164 totalDeleted := 0
165 for _, cache := range toDelete {
166 var count int
167 var err error
168 if id, ok := parseCacheID(cache); ok {
169 err = deleteCacheByID(client, repo, id)
170 count = 1
171 } else {
172 count, err = deleteCacheByKey(client, repo, cache, opts.Ref)
173 }
174
175 if err != nil {
176 if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
177 if httpErr.StatusCode == http.StatusNotFound {
178 if opts.Ref == "" {
179 err = fmt.Errorf("%s Could not find a cache matching %s in %s", cs.FailureIcon(), cache, repoName)
180 } else {
181 err = fmt.Errorf("%s Could not find a cache matching %s (with ref %s) in %s", cs.FailureIcon(), cache, opts.Ref, repoName)
182 }
183 } else {
184 err = fmt.Errorf("%s Failed to delete cache: %w", cs.FailureIcon(), err)
185 }
186 }
187 opts.IO.StopProgressIndicator()
188 return err
189 }
190
191 totalDeleted += count
192 }
193
194 opts.IO.StopProgressIndicator()
195
196 if opts.IO.IsStdoutTTY() {
197 fmt.Fprintf(opts.IO.Out, "%s Deleted %s from %s\n", cs.SuccessIcon(), text.Pluralize(totalDeleted, "cache"), repoName)
198 }
199
200 return nil
201}
202
203func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int64) error {
204 // returns HTTP 204 (NO CONTENT) on success

Callers 1

deleteRunFunction · 0.85

Calls 12

FullNameFunction · 0.92
PluralizeFunction · 0.92
parseCacheIDFunction · 0.85
deleteCacheByIDFunction · 0.85
deleteCacheByKeyFunction · 0.85
ColorSchemeMethod · 0.80
FailureIconMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconMethod · 0.80
ErrorfMethod · 0.65
StopProgressIndicatorMethod · 0.65

Tested by

no test coverage detected