From d930f06a27c6756adca30cf339bb2d476d058b66 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Mon, 16 Mar 2020 17:01:53 -0700 Subject: [PATCH] cli: added flags to control progress output --no-progress - disables progress completely --progress-update-interval=T - controls how frequently progress is updated Fixes #344 --- cli/cli_progress.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/cli_progress.go b/cli/cli_progress.go index c633a196e..b99258737 100644 --- a/cli/cli_progress.go +++ b/cli/cli_progress.go @@ -10,6 +10,11 @@ "github.com/kopia/kopia/snapshot/snapshotfs" ) +var ( + enableProgress = app.Flag("progress", "Enable progress bar").Hidden().Default("true").Bool() + progressUpdateInterval = app.Flag("progress-update-interval", "How ofter to update progress information").Hidden().Default("300ms").Duration() +) + const spinner = `|/-\` const hundredPercent = 100.0 @@ -78,9 +83,7 @@ func (p *cliProgress) maybeOutput() { nextOutputTimeUnixNano := atomic.LoadInt64(&p.nextOutputTimeUnixNano) if nowNano := time.Now().UnixNano(); nowNano > nextOutputTimeUnixNano { - const interval = 300 * time.Millisecond - - if atomic.CompareAndSwapInt64(&p.nextOutputTimeUnixNano, nextOutputTimeUnixNano, nowNano+interval.Nanoseconds()) { + if atomic.CompareAndSwapInt64(&p.nextOutputTimeUnixNano, nextOutputTimeUnixNano, nowNano+progressUpdateInterval.Nanoseconds()) { shouldOutput = true } } @@ -91,6 +94,10 @@ func (p *cliProgress) maybeOutput() { } func (p *cliProgress) output() { + if !*enableProgress { + return + } + hashedBytes := atomic.LoadInt64(&p.hashedBytes) cachedBytes := atomic.LoadInt64(&p.cachedBytes) uploadedBytes := atomic.LoadInt64(&p.uploadedBytes)