| 29 | } |
| 30 | |
| 31 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 32 | opts := &DeleteOptions{ |
| 33 | IO: f.IOStreams, |
| 34 | HttpClient: f.HttpClient, |
| 35 | } |
| 36 | |
| 37 | cmd := &cobra.Command{ |
| 38 | Use: "delete [<cache-id> | <cache-key> | --all]", |
| 39 | Short: "Delete GitHub Actions caches", |
| 40 | Long: heredoc.Docf(` |
| 41 | Delete GitHub Actions caches. |
| 42 | |
| 43 | Deletion requires authorization with the %[1]srepo%[1]s scope. |
| 44 | `, "`"), |
| 45 | Example: heredoc.Doc(` |
| 46 | # Delete a cache by id |
| 47 | $ gh cache delete 1234 |
| 48 | |
| 49 | # Delete a cache by key |
| 50 | $ gh cache delete cache-key |
| 51 | |
| 52 | # Delete a cache by id in a specific repo |
| 53 | $ gh cache delete 1234 --repo cli/cli |
| 54 | |
| 55 | # Delete a cache by key and branch ref |
| 56 | $ gh cache delete cache-key --ref refs/heads/feature-branch |
| 57 | |
| 58 | # Delete a cache by key and PR ref |
| 59 | $ gh cache delete cache-key --ref refs/pull/<PR-number>/merge |
| 60 | |
| 61 | # Delete all caches (exit code 1 on no caches) |
| 62 | $ gh cache delete --all |
| 63 | |
| 64 | # Delete all caches for a specific ref |
| 65 | $ gh cache delete --all --ref refs/pull/<PR-number>/merge |
| 66 | |
| 67 | # Delete all caches (exit code 0 on no caches) |
| 68 | $ gh cache delete --all --succeed-on-no-caches |
| 69 | `), |
| 70 | Args: cobra.MaximumNArgs(1), |
| 71 | RunE: func(cmd *cobra.Command, args []string) error { |
| 72 | // support -R/--repo flag |
| 73 | opts.BaseRepo = f.BaseRepo |
| 74 | |
| 75 | if err := cmdutil.MutuallyExclusive( |
| 76 | "specify only one of cache id, cache key, or --all", |
| 77 | opts.DeleteAll, len(args) > 0, |
| 78 | ); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | if !opts.DeleteAll && opts.SucceedOnNoCaches { |
| 83 | return cmdutil.FlagErrorf("--succeed-on-no-caches must be used in conjunction with --all") |
| 84 | } |
| 85 | |
| 86 | if opts.Ref != "" && len(args) == 0 && !opts.DeleteAll { |
| 87 | return cmdutil.FlagErrorf("must provide a cache key") |
| 88 | } |