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)
--- 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