NewSetDefaultCmd returns a new instance of SetDefaultCmd
(f *cmdutil.Factory, runF func(*SetDefaultOptions) error)
| 22 | |
| 23 | // NewSetDefaultCmd returns a new instance of SetDefaultCmd |
| 24 | func NewSetDefaultCmd(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *cobra.Command { |
| 25 | opts := &SetDefaultOptions{ |
| 26 | IO: f.IOStreams, |
| 27 | config: f.Config, |
| 28 | } |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "setdefault <profile>", |
| 31 | Args: validators.ExactArgs(1), |
| 32 | ValidArgsFunction: cmdutil.ConfiguredProfilesCompletionFunc(f), |
| 33 | Short: "Set the default profile", |
| 34 | Example: heredoc.Doc(` |
| 35 | # Set the default profile to "my-app" |
| 36 | $ algolia profile setdefault my-app |
| 37 | `), |
| 38 | RunE: func(cmd *cobra.Command, args []string) error { |
| 39 | opts.Profile = args[0] |
| 40 | |
| 41 | if !opts.config.ProfileExists(opts.Profile) { |
| 42 | return fmt.Errorf("the specified profile does not exist: '%s'", opts.Profile) |
| 43 | } |
| 44 | |
| 45 | if runF != nil { |
| 46 | return runF(opts) |
| 47 | } |
| 48 | |
| 49 | return runSetDefaultCmd(opts) |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | return cmd |
| 54 | } |
| 55 | |
| 56 | // runSetDefaultCmd executes the setdefault command |
| 57 | func runSetDefaultCmd(opts *SetDefaultOptions) error { |