| 26 | } |
| 27 | |
| 28 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 29 | opts := &DeleteOptions{ |
| 30 | IO: f.IOStreams, |
| 31 | Config: f.Config, |
| 32 | HttpClient: f.HttpClient, |
| 33 | } |
| 34 | |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "delete <variable-name>", |
| 37 | Short: "Delete variables", |
| 38 | Long: heredoc.Doc(` |
| 39 | Delete a variable on one of the following levels: |
| 40 | - repository (default): available to GitHub Actions runs or Dependabot in a repository |
| 41 | - environment: available to GitHub Actions runs for a deployment environment in a repository |
| 42 | - organization: available to GitHub Actions runs or Dependabot within an organization |
| 43 | `), |
| 44 | Args: cobra.ExactArgs(1), |
| 45 | RunE: func(cmd *cobra.Command, args []string) error { |
| 46 | // support `-R, --repo` override |
| 47 | opts.BaseRepo = f.BaseRepo |
| 48 | |
| 49 | if err := cmdutil.MutuallyExclusive("specify only one of `--org` or `--env`", opts.OrgName != "", opts.EnvName != ""); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | opts.VariableName = args[0] |
| 54 | |
| 55 | if runF != nil { |
| 56 | return runF(opts) |
| 57 | } |
| 58 | |
| 59 | return removeRun(opts) |
| 60 | }, |
| 61 | Aliases: []string{ |
| 62 | "remove", |
| 63 | }, |
| 64 | } |
| 65 | cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "Delete a variable for an organization") |
| 66 | cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "Delete a variable for an environment") |
| 67 | |
| 68 | return cmd |
| 69 | } |
| 70 | |
| 71 | func removeRun(opts *DeleteOptions) error { |
| 72 | c, err := opts.HttpClient() |