diff --git a/cmd/restic/cmd_backup_integration_test.go b/cmd/restic/cmd_backup_integration_test.go index 769a60c03..5dee23f17 100644 --- a/cmd/restic/cmd_backup_integration_test.go +++ b/cmd/restic/cmd_backup_integration_test.go @@ -24,7 +24,6 @@ func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts term := termstatus.New(gopts.stdout, gopts.stderr, gopts.Quiet) wg.Go(func() error { term.Run(ctx); return nil }) - gopts.stdout = io.Discard t.Logf("backing up %v in %v", target, dir) if dir != "" { cleanup := rtest.Chdir(t, dir) @@ -371,9 +370,7 @@ func TestBackupErrors(t *testing.T) { rtest.OK(t, os.Chmod(inaccessibleFile, 0644)) }() opts := BackupOptions{} - gopts := env.gopts - gopts.stderr = io.Discard - err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts) + err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, env.gopts) rtest.Assert(t, err != nil, "Assumed failure, but no error occurred.") rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned") testListSnapshots(t, env.gopts, 1) diff --git a/cmd/restic/cmd_cache.go b/cmd/restic/cmd_cache.go index 334063fdc..4a10d1027 100644 --- a/cmd/restic/cmd_cache.go +++ b/cmd/restic/cmd_cache.go @@ -155,7 +155,7 @@ func runCache(opts CacheOptions, gopts GlobalOptions, args []string) error { }) } - _ = tab.Write(gopts.stdout) + _ = tab.Write(globalOptions.stdout) Printf("%d cache dirs in %s\n", len(dirs), cachedir) return nil diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index deade6d22..a54200c45 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -167,20 +167,20 @@ func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string) error switch tpe { case "indexes": - return dumpIndexes(ctx, repo, gopts.stdout) + return dumpIndexes(ctx, repo, globalOptions.stdout) case "snapshots": - return debugPrintSnapshots(ctx, repo, gopts.stdout) + return debugPrintSnapshots(ctx, repo, globalOptions.stdout) case "packs": - return printPacks(ctx, repo, gopts.stdout) + return printPacks(ctx, repo, globalOptions.stdout) case "all": Printf("snapshots:\n") - err := debugPrintSnapshots(ctx, repo, gopts.stdout) + err := debugPrintSnapshots(ctx, repo, globalOptions.stdout) if err != nil { return err } Printf("\nindexes:\n") - err = dumpIndexes(ctx, repo, gopts.stdout) + err = dumpIndexes(ctx, repo, globalOptions.stdout) if err != nil { return err } diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index 0861a7103..3c59b9580 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -381,7 +381,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args [] } if gopts.JSON { - enc := json.NewEncoder(gopts.stdout) + enc := json.NewEncoder(globalOptions.stdout) c.printChange = func(change *Change) { err := enc.Encode(change) if err != nil { @@ -415,7 +415,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args [] updateBlobs(repo, stats.BlobsAfter.Sub(both).Sub(stats.BlobsCommon), &stats.Added) if gopts.JSON { - err := json.NewEncoder(gopts.stdout).Encode(stats) + err := json.NewEncoder(globalOptions.stdout).Encode(stats) if err != nil { Warnf("JSON encode failed: %v\n", err) } diff --git a/cmd/restic/cmd_diff_integration_test.go b/cmd/restic/cmd_diff_integration_test.go index c46f00f4f..8782053ed 100644 --- a/cmd/restic/cmd_diff_integration_test.go +++ b/cmd/restic/cmd_diff_integration_test.go @@ -16,8 +16,6 @@ import ( func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) { buf, err := withCaptureStdout(func() error { - gopts.stdout = globalOptions.stdout - opts := DiffOptions{ ShowMetadata: false, } diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index eb8e7adde..d8e64bc6a 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -193,7 +193,7 @@ func runForget(ctx context.Context, opts ForgetOptions, gopts GlobalOptions, arg for k, snapshotGroup := range snapshotGroups { if gopts.Verbose >= 1 && !gopts.JSON { - err = PrintSnapshotGroupHeader(gopts.stdout, k) + err = PrintSnapshotGroupHeader(globalOptions.stdout, k) if err != nil { return err } @@ -250,7 +250,7 @@ func runForget(ctx context.Context, opts ForgetOptions, gopts GlobalOptions, arg } if gopts.JSON && len(jsonGroups) > 0 { - err = printJSONForget(gopts.stdout, jsonGroups) + err = printJSONForget(globalOptions.stdout, jsonGroups) if err != nil { return err } diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 213c7e898..43de7ff89 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -123,7 +123,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] ID: s.Config().ID, Repository: location.StripPassword(gopts.Repo), } - return json.NewEncoder(gopts.stdout).Encode(status) + return json.NewEncoder(globalOptions.stdout).Encode(status) } return nil diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index aeaa750eb..e8c27381c 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -181,7 +181,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri ) if gopts.JSON { - enc := json.NewEncoder(gopts.stdout) + enc := json.NewEncoder(globalOptions.stdout) printSnapshot = func(sn *restic.Snapshot) { err := enc.Encode(lsSnapshot{ diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index ba3644ee7..889ac5e20 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -94,7 +94,7 @@ func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions } if gopts.JSON { - err := printSnapshotGroupJSON(gopts.stdout, snapshotGroups, grouped) + err := printSnapshotGroupJSON(globalOptions.stdout, snapshotGroups, grouped) if err != nil { Warnf("error printing snapshots: %v\n", err) } @@ -103,13 +103,13 @@ func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions for k, list := range snapshotGroups { if grouped { - err := PrintSnapshotGroupHeader(gopts.stdout, k) + err := PrintSnapshotGroupHeader(globalOptions.stdout, k) if err != nil { Warnf("error printing snapshots: %v\n", err) return nil } } - PrintSnapshots(gopts.stdout, list, nil, opts.Compact) + PrintSnapshots(globalOptions.stdout, list, nil, opts.Compact) } return nil