forked from TrueCloudLab/restic
Introduce Verbosef
This commit is contained in:
parent
4388474cdc
commit
a43733d552
5 changed files with 20 additions and 23 deletions
|
@ -234,7 +234,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||
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
|
||||
|
@ -245,11 +245,11 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||
}
|
||||
|
||||
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())
|
||||
|
||||
|
@ -271,7 +271,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cmd.global.Printf("snapshot %s saved\n", id.Str())
|
||||
cmd.global.Verbosef("snapshot %s saved\n", id.Str())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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.Printf("created restic backend %v at %s\n", s.Config.ID[:10], cmd.global.Repo)
|
||||
cmd.global.Printf("\n")
|
||||
cmd.global.Printf("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.Printf("irrecoverably lost.\n")
|
||||
cmd.global.Verbosef("created restic backend %v at %s\n", s.Config.ID[:10], cmd.global.Repo)
|
||||
cmd.global.Verbosef("\n")
|
||||
cmd.global.Verbosef("Please note that knowledge of your password is required to access\n")
|
||||
cmd.global.Verbosef("the repository. Losing your password means that your data is\n")
|
||||
cmd.global.Verbosef("irrecoverably lost.\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,14 +3,11 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
)
|
||||
|
||||
type CmdList struct {
|
||||
w io.Writer
|
||||
global *GlobalOptions
|
||||
}
|
||||
|
||||
|
@ -29,10 +26,6 @@ func (cmd CmdList) Usage() string {
|
|||
}
|
||||
|
||||
func (cmd CmdList) Execute(args []string) error {
|
||||
if cmd.w == nil {
|
||||
cmd.w = os.Stdout
|
||||
}
|
||||
|
||||
if len(args) != 1 {
|
||||
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) {
|
||||
fmt.Fprintln(cmd.w, blob.ID)
|
||||
cmd.global.Printf("%s\n", blob.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -70,7 +63,7 @@ func (cmd CmdList) Execute(args []string) error {
|
|||
}
|
||||
|
||||
for id := range s.List(t, nil) {
|
||||
fmt.Fprintf(cmd.w, "%s\n", id)
|
||||
cmd.global.Printf("%s\n", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -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)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,10 +30,6 @@ var globalOpts = GlobalOptions{stdout: os.Stdout}
|
|||
var parser = flags.NewParser(&globalOpts, flags.Default)
|
||||
|
||||
func (o GlobalOptions) Printf(format string, args ...interface{}) {
|
||||
if o.Quiet {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(o.stdout, format, args...)
|
||||
if err != nil {
|
||||
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 {
|
||||
if o.Quiet {
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue