From bb1e258bb72cbeba696e6da673c564b458f77cbc Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 4 Apr 2020 19:45:36 +0200 Subject: [PATCH] cat/stats: Get stdout from globalOptions --- cmd/restic/cmd_cat.go | 10 ++++------ cmd/restic/cmd_stats.go | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 01cb8d278..5c0e94d96 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "os" "github.com/spf13/cobra" @@ -83,9 +82,8 @@ func runCat(gopts GlobalOptions, args []string) error { return err } - _, err = os.Stdout.Write(append(buf, '\n')) - return err - + Println(string(buf)) + return nil case "snapshot": sn := &restic.Snapshot{} err = repo.LoadJSONUnpacked(gopts.ctx, restic.SnapshotFile, id, sn) @@ -162,7 +160,7 @@ func runCat(gopts GlobalOptions, args []string) error { Warnf("Warning: hash of data does not match ID, want\n %v\ngot:\n %v\n", id.String(), hash.String()) } - _, err = os.Stdout.Write(buf) + _, err = globalOptions.stdout.Write(buf) return err case "blob": @@ -177,7 +175,7 @@ func runCat(gopts GlobalOptions, args []string) error { return err } - _, err = os.Stdout.Write(buf) + _, err = globalOptions.stdout.Write(buf) return err } diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 6d3d7bd3d..7228bf6b0 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "os" "path/filepath" "github.com/restic/restic/internal/errors" @@ -149,7 +148,7 @@ func runStats(gopts GlobalOptions, args []string) error { } if gopts.JSON { - err = json.NewEncoder(os.Stdout).Encode(stats) + err = json.NewEncoder(globalOptions.stdout).Encode(stats) if err != nil { return fmt.Errorf("encoding output: %v", err) }