-
Notifications
You must be signed in to change notification settings - Fork 928
/
config.go
69 lines (59 loc) · 1.94 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package commands
import (
"github.com/cloudfoundry/cli/cf/command_metadata"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/flag_helpers"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/codegangsta/cli"
)
type ConfigCommands struct {
ui terminal.UI
config configuration.ReadWriter
}
func NewConfig(ui terminal.UI, config configuration.ReadWriter) ConfigCommands {
return ConfigCommands{ui: ui, config: config}
}
func (cmd ConfigCommands) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "config",
Description: T("write default values to the config"),
Usage: T("CF_NAME config [--async-timeout TIMEOUT_IN_MINUTES] [--trace true | false | path/to/file] [--color true | false]"),
Flags: []cli.Flag{
flag_helpers.NewIntFlag("async-timeout", T("Timeout for async HTTP requests")),
flag_helpers.NewStringFlag("trace", T("Trace HTTP requests")),
flag_helpers.NewStringFlag("color", T("Enable or disable color")),
},
}
}
func (cmd ConfigCommands) GetRequirements(_ requirements.Factory, _ *cli.Context) ([]requirements.Requirement, error) {
return nil, nil
}
func (cmd ConfigCommands) Run(context *cli.Context) {
if !context.IsSet("trace") && !context.IsSet("async-timeout") && !context.IsSet("color") {
cmd.ui.FailWithUsage(context)
return
}
if context.IsSet("async-timeout") {
asyncTimeout := context.Int("async-timeout")
if asyncTimeout < 0 {
cmd.ui.FailWithUsage(context)
}
cmd.config.SetAsyncTimeout(uint(asyncTimeout))
}
if context.IsSet("trace") {
cmd.config.SetTrace(context.String("trace"))
}
if context.IsSet("color") {
value := context.String("color")
switch value {
case "true":
cmd.config.SetColorEnabled("true")
case "false":
cmd.config.SetColorEnabled("false")
default:
cmd.ui.FailWithUsage(context)
}
}
}