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

Function runSetDefaultCmd

pkg/cmd/profile/setdefault/setdefault.go:57–90  ·  view source on GitHub ↗

runSetDefaultCmd executes the setdefault command

(opts *SetDefaultOptions)

Source from the content-addressed store, hash-verified

55
56// runSetDefaultCmd executes the setdefault command
57func runSetDefaultCmd(opts *SetDefaultOptions) error {
58 var defaultName string
59 for _, profile := range opts.config.ConfiguredProfiles() {
60 if profile.Default {
61 defaultName = profile.Name
62 }
63 }
64
65 err := opts.config.SetDefaultProfile(opts.Profile)
66 if err != nil {
67 return err
68 }
69
70 cs := opts.IO.ColorScheme()
71
72 opts.config.Profile().LoadDefault()
73 if err != nil {
74 return err
75 }
76
77 if opts.IO.IsStdoutTTY() {
78 if defaultName != "" {
79 if _, err = fmt.Fprintf(opts.IO.Out, "%s Default profile successfuly changed from '%s' to '%s'.\n", cs.SuccessIcon(), defaultName, opts.Profile); err != nil {
80 return err
81 }
82 } else {
83 if _, err = fmt.Fprintf(opts.IO.Out, "%s Default profile successfuly set to '%s'.\n", cs.SuccessIcon(), opts.Profile); err != nil {
84 return err
85 }
86 }
87 }
88
89 return nil
90}

Callers 1

NewSetDefaultCmdFunction · 0.85

Calls 7

ColorSchemeMethod · 0.80
LoadDefaultMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconMethod · 0.80
ConfiguredProfilesMethod · 0.65
SetDefaultProfileMethod · 0.65
ProfileMethod · 0.65

Tested by

no test coverage detected