Don't dump the configuration file if login failed
authorMikael Berthe <mikael@lilotux.net>
Sun, 23 Apr 2017 18:18:51 +0200
changeset 10 e4c490882126
parent 9 a6672fc5ee68
child 11 3884f5276808
Don't dump the configuration file if login failed If a username was provided and the authentication fails, the command "config dump" should abort. (Cf. issue #2)
cmd/config.go
--- a/cmd/config.go	Sun Apr 23 15:34:15 2017 +0200
+++ b/cmd/config.go	Sun Apr 23 18:18:51 2017 +0200
@@ -6,6 +6,8 @@
 package cmd
 
 import (
+	"os"
+
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
 
@@ -63,9 +65,12 @@
 	if err := madonInitClient(); err != nil {
 		return err
 	}
-	// Try to sign in, but don't mind if it fails
-	if err := madonLogin(); err != nil {
-		errPrint("Info: could not log in: %s", err)
+	// 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)
+			os.Exit(-1)
+		}
 	}
 
 	var p printer.ResourcePrinter