| 19 | } |
| 20 | |
| 21 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 22 | opts := &DeleteOptions{ |
| 23 | IO: f.IOStreams, |
| 24 | Config: f.Config, |
| 25 | } |
| 26 | |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "delete {<alias> | --all}", |
| 29 | Short: "Delete set aliases", |
| 30 | Args: cobra.MaximumNArgs(1), |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | if len(args) == 0 && !opts.All { |
| 33 | return cmdutil.FlagErrorf("specify an alias to delete or `--all`") |
| 34 | } |
| 35 | if len(args) > 0 && opts.All { |
| 36 | return cmdutil.FlagErrorf("cannot use `--all` with alias name") |
| 37 | } |
| 38 | if len(args) > 0 { |
| 39 | opts.Name = args[0] |
| 40 | } |
| 41 | if runF != nil { |
| 42 | return runF(opts) |
| 43 | } |
| 44 | return deleteRun(opts) |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | cmd.Flags().BoolVar(&opts.All, "all", false, "Delete all aliases") |
| 49 | |
| 50 | return cmd |
| 51 | } |
| 52 | |
| 53 | func deleteRun(opts *DeleteOptions) error { |
| 54 | cfg, err := opts.Config() |