cmd/config.go
changeset 91 02312ccc1fd3
parent 83 57afac822019
child 110 57843255fd1a
--- a/cmd/config.go	Sun May 07 19:30:24 2017 +0200
+++ b/cmd/config.go	Sun May 07 19:31:37 2017 +0200
@@ -42,6 +42,14 @@
 			return configDisplayToken()
 		},
 	},
+	&cobra.Command{
+		Use: "themes",
+		//Aliases: []string{},
+		Short: "Display available themes",
+		RunE: func(cmd *cobra.Command, args []string) error {
+			return configDisplayThemes()
+		},
+	},
 }
 
 const configurationTemplate = `---
@@ -68,7 +76,7 @@
 	// Try to sign in if a login was provided
 	if viper.GetString("token") != "" || viper.GetString("login") != "" {
 		if err := madonLogin(); err != nil {
-			errPrint("Error: could not log in: %s", err)
+			errPrint("Error: could not log in: %v", err)
 			os.Exit(-1)
 		}
 	}
@@ -89,7 +97,7 @@
 		p, err = getPrinter()
 	}
 	if err != nil {
-		errPrint("Error: %s", err.Error())
+		errPrint("Error: %v", err)
 		os.Exit(1)
 	}
 	return p.PrintObj(gClient, nil, "")
@@ -107,8 +115,32 @@
 
 	p, err := getPrinter()
 	if err != nil {
-		errPrint("Error: %s", err.Error())
+		errPrint("Error: %v", err)
 		os.Exit(1)
 	}
 	return p.PrintObj(gClient.UserToken, nil, "")
 }
+
+// configDisplayThemes lists the available themes
+// It is intended for shell completion.
+func configDisplayThemes() error {
+	var p printer.ResourcePrinter
+
+	themes, err := getThemes()
+	if err != nil {
+		errPrint("Error: %v", err)
+		os.Exit(1)
+	}
+
+	if getOutputFormat() == "plain" {
+		pOptions := printer.Options{"template": `{{printf "%s\n" .}}`}
+		p, err = printer.NewPrinterTemplate(pOptions)
+	} else {
+		p, err = getPrinter()
+	}
+	if err != nil {
+		errPrint("Error: %v", err)
+		os.Exit(1)
+	}
+	return p.PrintObj(themes, nil, "")
+}