mirror of
https://github.com/kopia/kopia.git
synced 2026-05-24 06:34:46 -04:00
cli: added flags to control progress output
--no-progress - disables progress completely --progress-update-interval=T - controls how frequently progress is updated Fixes #344
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user