2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-24 05:37:37 +00:00

always access stdout/stderr via globalOptions

This commit is contained in:
Michael Eischer 2023-05-07 22:21:56 +02:00
parent 4b3a0b4104
commit 7a268e4aba
9 changed files with 16 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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