diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 088b3afab..2ab9dc5e0 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -262,7 +262,7 @@ func (cmd CmdBackup) Execute(args []string) error { arch.Error = func(dir string, fi os.FileInfo, err error) error { // TODO: make ignoring errors configurable - fmt.Fprintf(os.Stderr, "\x1b[2K\rerror for %s: %v\n", dir, err) + cmd.global.Warnf("\x1b[2K\rerror for %s: %v\n", dir, err) return nil } diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index ef3fb577a..1f3697d4d 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "os" "path/filepath" "github.com/restic/restic" @@ -51,12 +50,11 @@ func (cmd CmdRestore) Execute(args []string) error { // create restorer res, err := restic.NewRestorer(s, id) if err != nil { - fmt.Fprintf(os.Stderr, "creating restorer failed: %v\n", err) - os.Exit(2) + cmd.global.Exitf(2, "creating restorer failed: %v\n", err) } res.Error = func(dir string, node *restic.Node, err error) error { - fmt.Fprintf(os.Stderr, "error for %s: %+v\n", dir, err) + cmd.global.Warnf("error for %s: %+v\n", dir, err) // if node.Type == "dir" { // if e, ok := err.(*os.PathError); ok { diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 79c9eaf98..3f20c9248 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -24,9 +24,10 @@ type GlobalOptions struct { password string stdout io.Writer + stderr io.Writer } -var globalOpts = GlobalOptions{stdout: os.Stdout} +var globalOpts = GlobalOptions{stdout: os.Stdout, stderr: os.Stderr} var parser = flags.NewParser(&globalOpts, flags.Default) func (o GlobalOptions) Printf(format string, args ...interface{}) { @@ -58,7 +59,7 @@ func (o GlobalOptions) ShowProgress() bool { } func (o GlobalOptions) Warnf(format string, args ...interface{}) { - _, err := fmt.Fprintf(os.Stderr, format, args...) + _, err := fmt.Fprintf(o.stderr, format, args...) if err != nil { fmt.Fprintf(os.Stderr, "unable to write to stderr: %v\n", err) os.Exit(100)