Update settings
authorMikael Berthe <mikael@lilotux.net>
Sun, 14 May 2017 10:52:22 +0200
changeset 135 55b4a119c7c6
parent 134 a057c44144a4
child 136 32430612b929
Update settings - Add setting default_theme - Rename output into default_output - Fix color setting (viper sometimes turns it into a boolean)
cmd/root.go
cmd/utils.go
--- a/cmd/root.go	Sat May 13 12:45:52 2017 +0200
+++ b/cmd/root.go	Sun May 14 10:52:22 2017 +0200
@@ -133,7 +133,7 @@
 	RootCmd.PersistentFlags().StringVarP(&login, "login", "L", "", "Instance user login")
 	RootCmd.PersistentFlags().StringVarP(&password, "password", "P", "", "Instance user password")
 	RootCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "User token")
-	RootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "plain",
+	RootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "",
 		"Output format (plain|json|yaml|template|theme)")
 	RootCmd.PersistentFlags().StringVar(&outputTemplate, "template", "",
 		"Go template (for output=template)")
@@ -145,9 +145,7 @@
 		"Color mode (auto|on|off; for output=template)")
 
 	// Configuration file bindings
-	viper.BindPFlag("output", RootCmd.PersistentFlags().Lookup("output"))
 	viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
-	// XXX viper.BindPFlag("apiKey", RootCmd.PersistentFlags().Lookup("api-key"))
 	viper.BindPFlag("instance", RootCmd.PersistentFlags().Lookup("instance"))
 	viper.BindPFlag("login", RootCmd.PersistentFlags().Lookup("login"))
 	viper.BindPFlag("password", RootCmd.PersistentFlags().Lookup("password"))
--- a/cmd/utils.go	Sat May 13 12:45:52 2017 +0200
+++ b/cmd/utils.go	Sun May 14 10:52:22 2017 +0200
@@ -21,7 +21,10 @@
 )
 
 func checkOutputFormat(cmd *cobra.Command, args []string) error {
-	of := viper.GetString("output")
+	of := outputFormat
+	if of == "" {
+		of = viper.GetString("default_output")
+	}
 	switch of {
 	case "", "plain", "json", "yaml", "template", "theme":
 		return nil // Accepted
@@ -31,9 +34,12 @@
 
 // getOutputFormat return the requested output format, defaulting to "plain".
 func getOutputFormat() string {
-	of := viper.GetString("output")
+	of := outputFormat
 	if of == "" {
-		of = "plain"
+		of = viper.GetString("default_output")
+		if of == "" {
+			of = "plain"
+		}
 	}
 	// Override format if a template is provided
 	if of == "plain" {
@@ -66,16 +72,20 @@
 
 	// Initialize color mode
 	switch viper.GetString("color") {
-	case "on", "yes", "force":
+	case "on", "true", "yes", "force":
 		opt["color_mode"] = "on"
-	case "off", "no":
+	case "off", "false", "no":
 		opt["color_mode"] = "off"
 	default:
 		opt["color_mode"] = "auto"
 	}
 
 	if of == "theme" {
-		opt["name"] = outputTheme
+		if outputTheme != "" {
+			opt["name"] = outputTheme
+		} else {
+			opt["name"] = viper.GetString("default_theme")
+		}
 		opt["template_directory"] = viper.GetString("template_directory")
 	} else if of == "template" {
 		opt["template"] = outputTemplate