sojuctl: don't use log.Fatalf in readPassword

This commit is contained in:
Simon Ser 2021-04-19 14:11:25 +02:00
parent 0d6d297027
commit c994ce7092
1 changed files with 4 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"flag" "flag"
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
@ -125,12 +126,13 @@ func readPassword() ([]byte, error) {
fmt.Printf("\n") fmt.Printf("\n")
} else { } else {
fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n") fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
// TODO: the buffering messes up repeated calls to readPassword
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
if !scanner.Scan() { if !scanner.Scan() {
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
log.Fatalf("failed to read password from stdin: %v", err) return nil, err
} }
log.Fatalf("failed to read password from stdin: stdin is empty") return nil, io.ErrUnexpectedEOF
} }
password = scanner.Bytes() password = scanner.Bytes()