| 36 | } |
| 37 | |
| 38 | func RmCommand() *cobra.Command { |
| 39 | opts := rmOpts{} |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "rm name1 name2 ...", |
| 42 | Aliases: []string{"delete", "erase", "remove"}, |
| 43 | Short: "Remove secrets from local keychain.", |
| 44 | Long: "Removes one or more named secrets from the local OS keychain. Use `--all` to remove every stored secret at once.", |
| 45 | Example: strings.Trim(rmExample, "\n"), |
| 46 | RunE: func(cmd *cobra.Command, args []string) error { |
| 47 | idList, err := validateArgs(args, opts) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | kc, err := StoreFrom(cmd.Context()) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | return runRm(cmd.Context(), cmd.OutOrStdout(), kc, idList, opts) |
| 56 | }, |
| 57 | } |
| 58 | flags := cmd.Flags() |
| 59 | flags.BoolVar(&opts.All, "all", false, "Remove all secrets") |
| 60 | return cmd |
| 61 | } |
| 62 | |
| 63 | func validateArgs(args []string, opts rmOpts) ([]store.ID, error) { |
| 64 | if (len(args) == 0 && !opts.All) || (len(args) > 0 && opts.All) { |