From 6cdb9a75e64fd0296d57f1015537443ecce0b2b2 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 13 Sep 2025 23:04:14 +0200 Subject: [PATCH] consider JSON flag in newTerminalProgressPrinter --- cmd/restic/cmd_check.go | 2 +- cmd/restic/cmd_forget.go | 6 +----- cmd/restic/cmd_migrate.go | 2 +- cmd/restic/cmd_prune.go | 2 +- cmd/restic/cmd_recover.go | 2 +- cmd/restic/cmd_repair_index.go | 2 +- cmd/restic/cmd_repair_packs.go | 2 +- cmd/restic/progress.go | 5 ++++- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 6bbaa2747..04e6fab82 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -228,7 +228,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args var printer progress.Printer if !gopts.JSON { - printer = newTerminalProgressPrinter(gopts.verbosity, term) + printer = newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) } else { printer = newJSONErrorPrinter(term) } diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index bef00ffa1..2075f3b61 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -194,11 +194,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption } defer unlock() - verbosity := gopts.verbosity - if gopts.JSON { - verbosity = 0 - } - printer := newTerminalProgressPrinter(verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) var snapshots restic.Snapshots removeSnIDs := restic.NewIDSet() diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index d4e7d0ac1..9f33749f9 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -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 { - printer := newTerminalProgressPrinter(gopts.verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false) if err != nil { diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index ff43d83c0..b3aa8431e 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -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") } - printer := newTerminalProgressPrinter(gopts.verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) printer.P("loading indexes...\n") // loading the index before the snapshots is ok, as we use an exclusive lock here diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index c1c71333f..cdb5c2a84 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -55,7 +55,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Termi } defer unlock() - printer := newTerminalProgressPrinter(gopts.verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) snapshotLister, err := restic.MemorizeList(ctx, repo, restic.SnapshotFile) if err != nil { diff --git a/cmd/restic/cmd_repair_index.go b/cmd/restic/cmd_repair_index.go index 079b322a9..8d9da36fb 100644 --- a/cmd/restic/cmd_repair_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -79,7 +79,7 @@ func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalO } defer unlock() - printer := newTerminalProgressPrinter(gopts.verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) err = repository.RepairIndex(ctx, repo, repository.RepairIndexOptions{ ReadAllPacks: opts.ReadAllPacks, diff --git a/cmd/restic/cmd_repair_packs.go b/cmd/restic/cmd_repair_packs.go index aaaa2f08f..72cf52b11 100644 --- a/cmd/restic/cmd_repair_packs.go +++ b/cmd/restic/cmd_repair_packs.go @@ -59,7 +59,7 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term *termstatus.T } defer unlock() - printer := newTerminalProgressPrinter(gopts.verbosity, term) + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) bar := newIndexTerminalProgress(gopts.Quiet, gopts.JSON, term) err = repo.LoadIndex(ctx, bar) diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index b2abd61d2..6c01cc0a2 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -120,7 +120,10 @@ func (t *terminalProgressPrinter) NewCounter(description string) *progress.Count 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{ term: term, Message: *ui.NewMessage(term, verbosity),