Browse Source

Send cli errors to stderr

Frederic Guillot 7 months ago
parent
commit
6869c6fe6f
4 changed files with 8 additions and 8 deletions
  1. 1 1
      cli/ask_credentials.go
  2. 2 2
      cli/create_admin.go
  3. 1 1
      cli/flush_sessions.go
  4. 4 4
      cli/reset_password.go

+ 1 - 1
cli/ask_credentials.go

@@ -17,7 +17,7 @@ func askCredentials() (string, string) {
 	fd := int(os.Stdin.Fd())
 
 	if !terminal.IsTerminal(fd) {
-		fmt.Fprintf(os.Stderr, "This is not a terminal, exiting.")
+		fmt.Fprintf(os.Stderr, "This is not a terminal, exiting.\n")
 		os.Exit(1)
 	}
 

+ 2 - 2
cli/create_admin.go

@@ -24,7 +24,7 @@ func createAdmin(store *storage.Storage) {
 	}
 
 	if err := user.ValidateUserCreation(); err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}
 
@@ -34,7 +34,7 @@ func createAdmin(store *storage.Storage) {
 	}
 
 	if err := store.CreateUser(user); err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}
 }

+ 1 - 1
cli/flush_sessions.go

@@ -14,7 +14,7 @@ import (
 func flushSessions(store *storage.Storage) {
 	fmt.Println("Flushing all sessions (disconnect users)")
 	if err := store.FlushAllSessions(); err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}
 }

+ 4 - 4
cli/reset_password.go

@@ -15,23 +15,23 @@ func resetPassword(store *storage.Storage) {
 	username, password := askCredentials()
 	user, err := store.UserByUsername(username)
 	if err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}
 
 	if user == nil {
-		fmt.Println("User not found!")
+		fmt.Fprintf(os.Stderr, "User not found!\n")
 		os.Exit(1)
 	}
 
 	user.Password = password
 	if err := user.ValidatePassword(); err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}
 
 	if err := store.UpdateUser(user); err != nil {
-		fmt.Println(err)
+		fmt.Fprintf(os.Stderr, "%v\n", err)
 		os.Exit(1)
 	}