consider JSON flag in newTerminalProgressPrinter

This commit is contained in:
Michael Eischer
2025-09-13 23:04:14 +02:00
parent 81fe559222
commit 6cdb9a75e6
8 changed files with 11 additions and 12 deletions

View File

@@ -228,7 +228,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
var printer progress.Printer var printer progress.Printer
if !gopts.JSON { if !gopts.JSON {
printer = newTerminalProgressPrinter(gopts.verbosity, term) printer = newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
} else { } else {
printer = newJSONErrorPrinter(term) printer = newJSONErrorPrinter(term)
} }

View File

@@ -194,11 +194,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
} }
defer unlock() defer unlock()
verbosity := gopts.verbosity printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
if gopts.JSON {
verbosity = 0
}
printer := newTerminalProgressPrinter(verbosity, term)
var snapshots restic.Snapshots var snapshots restic.Snapshots
removeSnIDs := restic.NewIDSet() removeSnIDs := restic.NewIDSet()

View File

@@ -136,7 +136,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptio
} }
func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error {
printer := newTerminalProgressPrinter(gopts.verbosity, term) printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
if err != nil { if err != nil {

View File

@@ -191,7 +191,7 @@ func runPruneWithRepo(ctx context.Context, opts PruneOptions, gopts GlobalOption
Print("warning: running prune without a cache, this may be very slow!\n") Print("warning: running prune without a cache, this may be very slow!\n")
} }
printer := newTerminalProgressPrinter(gopts.verbosity, term) printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer.P("loading indexes...\n") printer.P("loading indexes...\n")
// loading the index before the snapshots is ok, as we use an exclusive lock here // loading the index before the snapshots is ok, as we use an exclusive lock here

View File

@@ -55,7 +55,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Termi
} }
defer unlock() defer unlock()
printer := newTerminalProgressPrinter(gopts.verbosity, term) printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
snapshotLister, err := restic.MemorizeList(ctx, repo, restic.SnapshotFile) snapshotLister, err := restic.MemorizeList(ctx, repo, restic.SnapshotFile)
if err != nil { if err != nil {

View File

@@ -79,7 +79,7 @@ func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalO
} }
defer unlock() defer unlock()
printer := newTerminalProgressPrinter(gopts.verbosity, term) printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
err = repository.RepairIndex(ctx, repo, repository.RepairIndexOptions{ err = repository.RepairIndex(ctx, repo, repository.RepairIndexOptions{
ReadAllPacks: opts.ReadAllPacks, ReadAllPacks: opts.ReadAllPacks,

View File

@@ -59,7 +59,7 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term *termstatus.T
} }
defer unlock() defer unlock()
printer := newTerminalProgressPrinter(gopts.verbosity, term) printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term) bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term)
err = repo.LoadIndex(ctx, bar) err = repo.LoadIndex(ctx, bar)

View File

@@ -120,7 +120,10 @@ func (t *terminalProgressPrinter) NewCounter(description string) *progress.Count
return newTerminalProgressMax(t.show, 0, description, t.term) return newTerminalProgressMax(t.show, 0, description, t.term)
} }
func newTerminalProgressPrinter(verbosity uint, term *termstatus.Terminal) progress.Printer { func newTerminalProgressPrinter(json bool, verbosity uint, term *termstatus.Terminal) progress.Printer {
if json {
verbosity = 0
}
return &terminalProgressPrinter{ return &terminalProgressPrinter{
term: term, term: term,
Message: *ui.NewMessage(term, verbosity), Message: *ui.NewMessage(term, verbosity),