From fca4fe4459367c3b74485ce5d6148655dc8becda Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 2 May 2018 21:24:18 +0200 Subject: [PATCH] backup: Disable status output for --quiet --- cmd/restic/cmd_backup.go | 2 +- cmd/restic/integration_test.go | 2 +- internal/ui/termstatus/status.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 075e70245..562342000 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -48,7 +48,7 @@ given as the arguments. } var t tomb.Tomb - term := termstatus.New(globalOptions.stdout, globalOptions.stderr) + term := termstatus.New(globalOptions.stdout, globalOptions.stderr, globalOptions.Quiet) t.Go(func() error { term.Run(t.Context(globalOptions.ctx)); return nil }) err := runBackup(backupOptions, globalOptions, term, args) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 36a7670b1..92c75c851 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -59,7 +59,7 @@ func testRunBackup(t testing.TB, dir string, target []string, opts BackupOptions defer cancel() var wg errgroup.Group - term := termstatus.New(gopts.stdout, gopts.stderr) + term := termstatus.New(gopts.stdout, gopts.stderr, gopts.Quiet) wg.Go(func() error { term.Run(ctx); return nil }) gopts.stdout = ioutil.Discard diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index 6682430e8..7a0c6cfb1 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -44,8 +44,9 @@ type fder interface { // a file (e.g. via shell output redirection) or is just an io.Writer (not the // open *os.File for stdout), no status lines are printed. The status lines and // normal output (via Print/Printf) are written to wr, error messages are -// written to errWriter. -func New(wr io.Writer, errWriter io.Writer) *Terminal { +// written to errWriter. If disableStatus is set to true, no status messages +// are printed even if the terminal supports it. +func New(wr io.Writer, errWriter io.Writer, disableStatus bool) *Terminal { t := &Terminal{ wr: bufio.NewWriter(wr), errWriter: errWriter, @@ -54,6 +55,10 @@ func New(wr io.Writer, errWriter io.Writer) *Terminal { status: make(chan status), } + if disableStatus { + return t + } + if d, ok := wr.(fder); ok && canUpdateStatus(d.Fd()) { // only use the fancy status code when we're running on a real terminal. t.canUpdateStatus = true