-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
47 lines (41 loc) · 1.1 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
package cli
type Config struct {
Cli CliConfig `json:"cli" yaml:"Cli"`
}
type CliConfig struct {
Name string `json:"name" yaml:"Name"`
Version string `json:"version" yaml:"Version"`
Description string `json:"description" yaml:"Description"`
Usage string `json:"usage" yaml:"Usage"`
NoFlags bool `json:"no_flags" yaml:"NoFlags"`
ArgPrefix string `json:"arg_prefix" yaml:"ArgPrefix"`
Plugin string `json:"plugin" yaml:"Plugin"`
ConfigFile string `json:"config_file" yaml:"ConfigFile"`
Flags []Flag `json:"-" yaml:"-"`
}
func NewConfig() *Config {
return &Config{
Cli: CliConfig{
NoFlags: false,
ArgPrefix: "",
Plugin: "",
ConfigFile: "",
},
}
}
func (d *Config) Merge(src *Config) error {
def := NewConfig()
if src.Cli.NoFlags != def.Cli.NoFlags {
d.Cli.NoFlags = src.Cli.NoFlags
}
if src.Cli.ArgPrefix != def.Cli.ArgPrefix {
d.Cli.ArgPrefix = src.Cli.ArgPrefix
}
if src.Cli.Plugin != def.Cli.Plugin {
d.Cli.Plugin = src.Cli.Plugin
}
if src.Cli.ConfigFile != def.Cli.ConfigFile {
d.Cli.ConfigFile = src.Cli.ConfigFile
}
return nil
}