MCPcopy
hub / github.com/cli/cli / deleteCaches

Function deleteCaches

pkg/cmd/cache/delete/delete.go:159–202  ·  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 var httpErr api.HTTPError
177 if errors.As(err, &httpErr) {
178 if httpErr.StatusCode == http.StatusNotFound {
179 if opts.Ref == "" {
180 err = fmt.Errorf("%s Could not find a cache matching %s in %s", cs.FailureIcon(), cache, repoName)
181 } else {
182 err = fmt.Errorf("%s Could not find a cache matching %s (with ref %s) in %s", cs.FailureIcon(), cache, opts.Ref, repoName)
183 }
184 } else {
185 err = fmt.Errorf("%s Failed to delete cache: %w", cs.FailureIcon(), err)
186 }
187 }
188 opts.IO.StopProgressIndicator()
189 return err
190 }
191
192 totalDeleted += count
193 }
194
195 opts.IO.StopProgressIndicator()
196
197 if opts.IO.IsStdoutTTY() {
198 fmt.Fprintf(opts.IO.Out, "%s Deleted %s from %s\n", cs.SuccessIcon(), text.Pluralize(totalDeleted, "cache"), repoName)
199 }
200
201 return nil
202}
203
204func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int64) error {
205 // 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