in config/config_tool.go [43:101]
func ConfigTool(configMap ConfigMap) error {
flag := flag.NewFlagSet("config", flag.ExitOnError)
var helpFlag bool
var dumpFlag bool
var removeFlag bool
flag.Usage = printConfigToolUsage
flag.BoolVar(&helpFlag, "h", false, "show this help")
flag.BoolVar(&helpFlag, "help", false, "show this help")
flag.BoolVar(&dumpFlag, "dump", false, "dump the config file")
flag.BoolVar(&dumpFlag, "d", false, "dump the config file")
flag.BoolVar(&removeFlag, "remove", false, "remove config values")
flag.BoolVar(&removeFlag, "r", false, "remove config values")
err := flag.Parse(os.Args[1:])
if err != nil {
return err
}
if helpFlag {
flag.Usage()
return nil
}
if dumpFlag {
dumped := configMap.Flatten()
for k, v := range dumped {
fmt.Printf("%s=%s\n", k, v)
}
return nil
}
// Get the input string from the remaining command line arguments
input := flag.Args()
if len(input) == 0 {
flag.Usage()
return nil
}
var cErr error
noAssigns := inputWithoutAssigns(input)
if removeFlag {
cErr = removeInConfigJSON(configMap, input)
} else if noAssigns {
// print the values and return
return printValues(configMap, input)
} else {
cErr = insertInConfigJSON(configMap, input)
}
if cErr != nil {
return cErr
}
return configMap.SaveConfig()
}