2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-06 19:10:49 +00:00

Introduce Verbosef

This commit is contained in:
Alexander Neumann 2015-06-21 13:25:26 +02:00
parent 4388474cdc
commit a43733d552
5 changed files with 20 additions and 23 deletions

View File

@ -234,7 +234,7 @@ func (cmd CmdBackup) Execute(args []string) error {
return fmt.Errorf("invalid id %q: %v", cmd.Parent, err) return fmt.Errorf("invalid id %q: %v", cmd.Parent, err)
} }
cmd.global.Printf("found parent snapshot %v\n", parentSnapshotID.Str()) cmd.global.Verbosef("found parent snapshot %v\n", parentSnapshotID.Str())
} }
// Find last snapshot to set it as parent, if not already set // Find last snapshot to set it as parent, if not already set
@ -245,11 +245,11 @@ func (cmd CmdBackup) Execute(args []string) error {
} }
if parentSnapshotID != nil { if parentSnapshotID != nil {
cmd.global.Printf("using parent snapshot %v\n", parentSnapshotID) cmd.global.Verbosef("using parent snapshot %v\n", parentSnapshotID)
} }
} }
cmd.global.Printf("scan %v\n", target) cmd.global.Verbosef("scan %v\n", target)
stat, err := restic.Scan(target, cmd.newScanProgress()) stat, err := restic.Scan(target, cmd.newScanProgress())
@ -271,7 +271,7 @@ func (cmd CmdBackup) Execute(args []string) error {
return err return err
} }
cmd.global.Printf("snapshot %s saved\n", id.Str()) cmd.global.Verbosef("snapshot %s saved\n", id.Str())
return nil return nil
} }

View File

@ -32,11 +32,11 @@ func (cmd CmdInit) Execute(args []string) error {
cmd.global.Exitf(1, "creating key in backend at %s failed: %v\n", cmd.global.Repo, err) cmd.global.Exitf(1, "creating key in backend at %s failed: %v\n", cmd.global.Repo, err)
} }
cmd.global.Printf("created restic backend %v at %s\n", s.Config.ID[:10], cmd.global.Repo) cmd.global.Verbosef("created restic backend %v at %s\n", s.Config.ID[:10], cmd.global.Repo)
cmd.global.Printf("\n") cmd.global.Verbosef("\n")
cmd.global.Printf("Please note that knowledge of your password is required to access\n") cmd.global.Verbosef("Please note that knowledge of your password is required to access\n")
cmd.global.Printf("the repository. Losing your password means that your data is\n") cmd.global.Verbosef("the repository. Losing your password means that your data is\n")
cmd.global.Printf("irrecoverably lost.\n") cmd.global.Verbosef("irrecoverably lost.\n")
return nil return nil
} }

View File

@ -3,14 +3,11 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"os"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
) )
type CmdList struct { type CmdList struct {
w io.Writer
global *GlobalOptions global *GlobalOptions
} }
@ -29,10 +26,6 @@ func (cmd CmdList) Usage() string {
} }
func (cmd CmdList) Execute(args []string) error { func (cmd CmdList) Execute(args []string) error {
if cmd.w == nil {
cmd.w = os.Stdout
}
if len(args) != 1 { if len(args) != 1 {
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage()) return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
} }
@ -51,7 +44,7 @@ func (cmd CmdList) Execute(args []string) error {
} }
for blob := range s.Index().Each(nil) { for blob := range s.Index().Each(nil) {
fmt.Fprintln(cmd.w, blob.ID) cmd.global.Printf("%s\n", blob.ID)
} }
return nil return nil
@ -70,7 +63,7 @@ func (cmd CmdList) Execute(args []string) error {
} }
for id := range s.List(t, nil) { for id := range s.List(t, nil) {
fmt.Fprintf(cmd.w, "%s\n", id) cmd.global.Printf("%s\n", id)
} }
return nil return nil

View File

@ -83,7 +83,7 @@ func (cmd CmdRestore) Execute(args []string) error {
} }
} }
cmd.global.Printf("restoring %s to %s\n", res.Snapshot(), target) cmd.global.Verbosef("restoring %s to %s\n", res.Snapshot(), target)
err = res.RestoreTo(target) err = res.RestoreTo(target)
if err != nil { if err != nil {

View File

@ -30,10 +30,6 @@ var globalOpts = GlobalOptions{stdout: os.Stdout}
var parser = flags.NewParser(&globalOpts, flags.Default) var parser = flags.NewParser(&globalOpts, flags.Default)
func (o GlobalOptions) Printf(format string, args ...interface{}) { func (o GlobalOptions) Printf(format string, args ...interface{}) {
if o.Quiet {
return
}
_, err := fmt.Fprintf(o.stdout, format, args...) _, err := fmt.Fprintf(o.stdout, format, args...)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err) fmt.Fprintf(os.Stderr, "unable to write to stdout: %v\n", err)
@ -41,6 +37,14 @@ func (o GlobalOptions) Printf(format string, args ...interface{}) {
} }
} }
func (o GlobalOptions) Verbosef(format string, args ...interface{}) {
if o.Quiet {
return
}
o.Printf(format, args...)
}
func (o GlobalOptions) ShowProgress() bool { func (o GlobalOptions) ShowProgress() bool {
if o.Quiet { if o.Quiet {
return false return false