MCPcopy Create free account
hub / github.com/algolia/cli / NewSetDefaultCmd

Function NewSetDefaultCmd

pkg/cmd/profile/setdefault/setdefault.go:24–54  ·  view source on GitHub ↗

NewSetDefaultCmd returns a new instance of SetDefaultCmd

(f *cmdutil.Factory, runF func(*SetDefaultOptions) error)

Source from the content-addressed store, hash-verified

22
23// NewSetDefaultCmd returns a new instance of SetDefaultCmd
24func 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
57func runSetDefaultCmd(opts *SetDefaultOptions) error {

Callers 2

NewProfileCmdFunction · 0.92
Test_runSetDefaultCmdFunction · 0.85

Calls 5

ExactArgsFunction · 0.92
runSetDefaultCmdFunction · 0.85
ProfileExistsMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

Test_runSetDefaultCmdFunction · 0.68