diff --git a/cmd/output.go b/cmd/output.go index 9a023691..b697da95 100644 --- a/cmd/output.go +++ b/cmd/output.go @@ -37,7 +37,7 @@ func jsonify(value interface{}, format string) string { if reflect.TypeOf(value).Kind() == reflect.Map || reflect.TypeOf(value).Kind() == reflect.Slice { var jsonStr []byte var err error - if (format == "text") { + if format == "text" { jsonStr, err = json.MarshalIndent(value, "", "") } else { jsonStr, err = json.Marshal(value) diff --git a/cmd/set.go b/cmd/set.go index c4269489..ee7c7374 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -18,10 +18,10 @@ package cmd import ( + "errors" "fmt" "reflect" "strings" - "errors" "github.com/apache/cloudstack-cloudmonkey/config" ) @@ -64,7 +64,7 @@ func init() { validArgs := r.Command.SubCommands[subCommand] if len(validArgs) != 0 && subCommand != "timeout" { if !config.CheckIfValuePresent(validArgs, value) { - return errors.New("Invalid value set for " + subCommand +". Supported values: " + strings.Join(validArgs, ", ") ) + return errors.New("Invalid value set for " + subCommand + ". Supported values: " + strings.Join(validArgs, ", ")) } } r.Config.UpdateConfig(subCommand, value, true) diff --git a/cmk.go b/cmk.go index b614b95e..ff9325eb 100644 --- a/cmk.go +++ b/cmk.go @@ -42,7 +42,7 @@ func init() { func main() { validFormats := strings.Join(config.GetOutputFormats(), ",") - outputFormat := flag.String("o", "", "output format: " + validFormats) + outputFormat := flag.String("o", "", "output format: "+validFormats) showVersion := flag.Bool("v", false, "show version") debug := flag.Bool("d", false, "enable debug mode") profile := flag.String("p", "", "server profile") diff --git a/config/config.go b/config/config.go index cca7913c..5be1336a 100644 --- a/config/config.go +++ b/config/config.go @@ -35,12 +35,12 @@ import ( // Output formats const ( - COLUMN = "column" - CSV = "csv" - JSON = "json" - TABLE = "table" - TEXT = "text" - DEFAULT= "default" + COLUMN = "column" + CSV = "csv" + JSON = "json" + TABLE = "table" + TEXT = "text" + DEFAULT = "default" ) // ServerProfile describes a management server @@ -77,7 +77,7 @@ type Config struct { } func GetOutputFormats() []string { - return []string {"column", "csv", "json", "table", "text", "default"} + return []string{"column", "csv", "json", "table", "text", "default"} } func CheckIfValuePresent(dataset []string, element string) bool { @@ -88,6 +88,7 @@ func CheckIfValuePresent(dataset []string, element string) bool { } return false } + // CacheFile returns the path to the cache file for a server profile func (c Config) CacheFile() string { cacheDir := path.Join(c.Dir, "profiles") @@ -102,7 +103,7 @@ func (c Config) CacheFile() string { func hasAccess(path string) bool { status := true file, err := os.Open(path) - if (err != nil) { + if err != nil { status = false } file.Close() @@ -136,12 +137,12 @@ func getDefaultConfigDir() string { func defaultCoreConfig() Core { return Core{ - Prompt: "🐱", - AsyncBlock: true, - Timeout: 1800, - Output: JSON, - VerifyCert: true, - ProfileName: "localcloud", + Prompt: "🐱", + AsyncBlock: true, + Timeout: 1800, + Output: JSON, + VerifyCert: true, + ProfileName: "localcloud", AutoComplete: true, } } @@ -253,7 +254,7 @@ func saveConfig(cfg *Config) *Config { // Update core := new(Core) conf.Section(ini.DEFAULT_SECTION).MapTo(core) - if (!conf.Section(ini.DEFAULT_SECTION).HasKey("autocomplete")) { + if !conf.Section(ini.DEFAULT_SECTION).HasKey("autocomplete") { core.AutoComplete = true } cfg.Core = core