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
if !gopts.JSON {
printer = newTerminalProgressPrinter(gopts.verbosity, term)
printer = newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
} else {
printer = newJSONErrorPrinter(term)
}

View File

@@ -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()

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 {
printer := newTerminalProgressPrinter(gopts.verbosity, term)
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
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")
}
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

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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)

View File

@@ -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),