mirror of
https://github.com/restic/restic.git
synced 2024-12-24 08:44:52 +00:00
Output warnings/errors to configurable writer
This commit is contained in:
parent
cfaf8ab8a6
commit
675f341b6d
3 changed files with 6 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue