From 55e60037496dcded078459dd58fd055f0f107f56 Mon Sep 17 00:00:00 2001 From: Anton Lindstrom Date: Wed, 4 Oct 2017 13:45:05 +0200 Subject: [PATCH 1/2] Add password successful feedback This adds some feedback when entering the password on the command line. When the password is entered and supplied through stdin (and stdout is a terminal) then the a message saying `password is correct` if correct is printed. --- cmd/restic/global.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 217d6f732..a60486426 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -132,6 +132,20 @@ func restoreTerminal() { }) } +// shouldOutputPasswordSuccessful returns true if the password is supplied +// interactively and the stdout is a terminal. +func shouldOutputPasswordSuccessful() bool { + if globalOptions.PasswordFile != "" { + return false + } + + if os.Getenv("RESTIC_PASSWORD") != "" { + return false + } + + return stdoutIsTerminal() +} + // ClearLine creates a platform dependent string to clear the current // line, so it can be overwritten. ANSI sequences are not supported on // current windows cmd shell. @@ -326,6 +340,10 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) { return nil, err } + if shouldOutputPasswordSuccessful() { + Verbosef("password is correct\n") + } + if opts.NoCache { return s, nil } From a7baea05228cfb78b36cf88b85b5e4c6e81419de Mon Sep 17 00:00:00 2001 From: Anton Lindstrom Date: Wed, 4 Oct 2017 14:55:04 +0200 Subject: [PATCH 2/2] Output password successful on terminal stdout This removes the conditions that checks if the password is supplied through environment variable or file and outputs password is successful on terminal and when --quiet is not supplied. --- cmd/restic/global.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index a60486426..f63052011 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -132,20 +132,6 @@ func restoreTerminal() { }) } -// shouldOutputPasswordSuccessful returns true if the password is supplied -// interactively and the stdout is a terminal. -func shouldOutputPasswordSuccessful() bool { - if globalOptions.PasswordFile != "" { - return false - } - - if os.Getenv("RESTIC_PASSWORD") != "" { - return false - } - - return stdoutIsTerminal() -} - // ClearLine creates a platform dependent string to clear the current // line, so it can be overwritten. ANSI sequences are not supported on // current windows cmd shell. @@ -340,7 +326,7 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) { return nil, err } - if shouldOutputPasswordSuccessful() { + if stdoutIsTerminal() { Verbosef("password is correct\n") }