feat(cache delete): allow for delete all caches for a ref

Signed-off-by: David van der Spek <david.vanderspek@flyrlabs.com>
This commit is contained in:
David van der Spek 2025-11-05 15:21:20 +01:00
parent 2728635b43
commit 6a798e76e1

View file

@ -61,6 +61,9 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
# Delete all caches (exit code 1 on no caches)
$ gh cache delete --all
# Delete all caches for a specific ref
$ gh cache delete --all --ref refs/pull/<PR-number>/merge
# Delete all caches (exit code 0 on no caches)
$ gh cache delete --all --succeed-on-no-caches
`),
@ -76,18 +79,11 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
return err
}
if err := cmdutil.MutuallyExclusive(
"--ref cannot be used with --all",
opts.DeleteAll, opts.Ref != "",
); err != nil {
return err
}
if !opts.DeleteAll && opts.SucceedOnNoCaches {
return cmdutil.FlagErrorf("--succeed-on-no-caches must be used in conjunction with --all")
}
if opts.Ref != "" && len(args) == 0 {
if opts.Ref != "" && len(args) == 0 && !opts.DeleteAll {
return cmdutil.FlagErrorf("must provide a cache key")
}
@ -135,7 +131,7 @@ func deleteRun(opts *DeleteOptions) error {
var toDelete []string
if opts.DeleteAll {
opts.IO.StartProgressIndicator()
caches, err := shared.GetCaches(client, repo, shared.GetCachesOptions{Limit: -1})
caches, err := shared.GetCaches(client, repo, shared.GetCachesOptions{Limit: -1, Ref: opts.Ref})
opts.IO.StopProgressIndicator()
if err != nil {
return err