MCPcopy
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/config.go:53–108  ·  view source on GitHub ↗
(context flags.FlagContext)

Source from the content-addressed store, hash-verified

51}
52
53func (cmd *ConfigCommands) Execute(context flags.FlagContext) error {
54 if !context.IsSet("trace") && !context.IsSet("async-timeout") && !context.IsSet("color") && !context.IsSet("locale") {
55 return errors.New(T("Incorrect Usage") + "\n\n" + commandregistry.Commands.CommandUsage("config"))
56 }
57
58 if context.IsSet("async-timeout") {
59 asyncTimeout := context.Int("async-timeout")
60 if asyncTimeout < 0 {
61 return errors.New(T("Incorrect Usage") + "\n\n" + commandregistry.Commands.CommandUsage("config"))
62 }
63
64 cmd.config.SetAsyncTimeout(uint(asyncTimeout))
65 }
66
67 if context.IsSet("trace") {
68 cmd.config.SetTrace(context.String("trace"))
69 }
70
71 if context.IsSet("color") {
72 value := context.String("color")
73 switch value {
74 case "true":
75 cmd.config.SetColorEnabled("true")
76 case "false":
77 cmd.config.SetColorEnabled("false")
78 default:
79 return errors.New(T("Incorrect Usage") + "\n\n" + commandregistry.Commands.CommandUsage("config"))
80 }
81 }
82
83 if context.IsSet("locale") {
84 locale := context.String("locale")
85
86 if locale == "CLEAR" {
87 cmd.config.SetLocale("")
88 return nil
89 }
90
91 if IsSupportedLocale(locale) {
92 cmd.config.SetLocale(locale)
93 return nil
94 }
95
96 unsupportedLocaleMessage := T("Could not find locale '{{.UnsupportedLocale}}'. The known locales are:\n", map[string]interface{}{
97 "UnsupportedLocale": locale,
98 })
99 supportedLocales := SupportedLocales()
100 sort.Strings(supportedLocales)
101 for i := range supportedLocales {
102 unsupportedLocaleMessage = unsupportedLocaleMessage + "\n" + supportedLocales[i]
103 }
104
105 return errors.New(unsupportedLocaleMessage)
106 }
107 return nil
108}

Callers

nothing calls this directly

Calls 10

IsSupportedLocaleFunction · 0.85
SupportedLocalesFunction · 0.85
CommandUsageMethod · 0.80
IsSetMethod · 0.65
IntMethod · 0.65
SetAsyncTimeoutMethod · 0.65
SetTraceMethod · 0.65
StringMethod · 0.65
SetColorEnabledMethod · 0.65
SetLocaleMethod · 0.65

Tested by

no test coverage detected