1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-25 17:27:25 +00:00

cat/stats: Get stdout from globalOptions

This commit is contained in:
Michael Eischer 2020-04-04 19:45:36 +02:00
parent 182655bc88
commit bb1e258bb7
2 changed files with 5 additions and 8 deletions

View file

@ -2,7 +2,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -83,9 +82,8 @@ func runCat(gopts GlobalOptions, args []string) error {
return err return err
} }
_, err = os.Stdout.Write(append(buf, '\n')) Println(string(buf))
return err return nil
case "snapshot": case "snapshot":
sn := &restic.Snapshot{} sn := &restic.Snapshot{}
err = repo.LoadJSONUnpacked(gopts.ctx, restic.SnapshotFile, id, sn) 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()) 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 return err
case "blob": case "blob":
@ -177,7 +175,7 @@ func runCat(gopts GlobalOptions, args []string) error {
return err return err
} }
_, err = os.Stdout.Write(buf) _, err = globalOptions.stdout.Write(buf)
return err return err
} }

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
@ -149,7 +148,7 @@ func runStats(gopts GlobalOptions, args []string) error {
} }
if gopts.JSON { if gopts.JSON {
err = json.NewEncoder(os.Stdout).Encode(stats) err = json.NewEncoder(globalOptions.stdout).Encode(stats)
if err != nil { if err != nil {
return fmt.Errorf("encoding output: %v", err) return fmt.Errorf("encoding output: %v", err)
} }