Print password prompts to stderr
This makes rclone with encrypted config better suited for use in pipelines. E.g.: $ rclone lsl mydrive:Some/Dir | sort -k 4 If the password prompt ("Enter configuration password") is printed to stdout, it will be swallowed by sort. By printing it to stderr, you still see the prompt, without sacrificing compatibility with the unix pipeline.
This commit is contained in:
parent
82b8d68ffb
commit
66e8c1600e
2 changed files with 5 additions and 5 deletions
|
@ -516,15 +516,15 @@ func checkPassword(password string) (string, error) {
|
||||||
|
|
||||||
// GetPassword asks the user for a password with the prompt given.
|
// GetPassword asks the user for a password with the prompt given.
|
||||||
func GetPassword(prompt string) string {
|
func GetPassword(prompt string) string {
|
||||||
fmt.Println(prompt)
|
fmt.Fprintln(os.Stderr, prompt)
|
||||||
for {
|
for {
|
||||||
fmt.Print("password:")
|
fmt.Fprint(os.Stderr, "password:")
|
||||||
password := ReadPassword()
|
password := ReadPassword()
|
||||||
password, err := checkPassword(password)
|
password, err := checkPassword(password)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return password
|
return password
|
||||||
}
|
}
|
||||||
fmt.Printf("Bad password: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Bad password: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ func getConfigPassword(q string) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Error:", err)
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// ReadPassword reads a password without echoing it to the terminal.
|
// ReadPassword reads a password without echoing it to the terminal.
|
||||||
func ReadPassword() string {
|
func ReadPassword() string {
|
||||||
line, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
line, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||||
fmt.Println("")
|
fmt.Fprintln(os.Stderr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to read password: %v", err)
|
log.Fatalf("Failed to read password: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue