(context flags.FlagContext)
| 51 | } |
| 52 | |
| 53 | func (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 | } |
nothing calls this directly
no test coverage detected