mirror of
https://github.com/restic/restic.git
synced 2025-03-30 00:00:14 +01:00
ui/progress: extend Printer interface with print to stdout method
This commit is contained in:
parent
89909d41aa
commit
f7f48b3026
3 changed files with 23 additions and 4 deletions
|
@ -262,10 +262,10 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
|
|||
for _, hint := range hints {
|
||||
switch hint.(type) {
|
||||
case *checker.ErrDuplicatePacks:
|
||||
term.Print(hint.Error())
|
||||
printer.S("%s", hint.Error())
|
||||
summary.HintRepairIndex = true
|
||||
case *checker.ErrMixedPack:
|
||||
term.Print(hint.Error())
|
||||
printer.S("%s", hint.Error())
|
||||
summary.HintPrune = true
|
||||
default:
|
||||
printer.E("error: %v\n", hint)
|
||||
|
@ -274,10 +274,10 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
|
|||
}
|
||||
|
||||
if summary.HintRepairIndex {
|
||||
term.Print("Duplicate packs are non-critical, you can run `restic repair index' to correct this.\n")
|
||||
printer.S("Duplicate packs are non-critical, you can run `restic repair index' to correct this.\n")
|
||||
}
|
||||
if summary.HintPrune {
|
||||
term.Print("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n")
|
||||
printer.S("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n")
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
|
@ -534,6 +534,7 @@ func (p *jsonErrorPrinter) E(msg string, args ...interface{}) {
|
|||
}
|
||||
p.term.Error(ui.ToJSONString(status))
|
||||
}
|
||||
func (*jsonErrorPrinter) S(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) P(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) V(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) VV(_ string, _ ...interface{}) {}
|
||||
|
|
|
@ -24,6 +24,12 @@ func (m *Message) E(msg string, args ...interface{}) {
|
|||
m.term.Error(fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
// S prints a message, this is should only be used for very important messages
|
||||
// that are not errors.
|
||||
func (m *Message) S(msg string, args ...interface{}) {
|
||||
m.term.Print(fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
// P prints a message if verbosity >= 1, this is used for normal messages which
|
||||
// are not errors.
|
||||
func (m *Message) P(msg string, args ...interface{}) {
|
||||
|
|
|
@ -8,9 +8,15 @@ import "testing"
|
|||
type Printer interface {
|
||||
NewCounter(description string) *Counter
|
||||
|
||||
// E prints to stderr
|
||||
E(msg string, args ...interface{})
|
||||
// S prints to stdout
|
||||
S(msg string, args ...interface{})
|
||||
// P prints to stdout unless quiet was passed
|
||||
P(msg string, args ...interface{})
|
||||
// V prints to stdout if verbose is set once
|
||||
V(msg string, args ...interface{})
|
||||
// VV prints to stdout if verbose is set twice
|
||||
VV(msg string, args ...interface{})
|
||||
}
|
||||
|
||||
|
@ -25,6 +31,8 @@ func (*NoopPrinter) NewCounter(_ string) *Counter {
|
|||
|
||||
func (*NoopPrinter) E(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*NoopPrinter) S(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*NoopPrinter) P(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*NoopPrinter) V(_ string, _ ...interface{}) {}
|
||||
|
@ -52,6 +60,10 @@ func (p *TestPrinter) E(msg string, args ...interface{}) {
|
|||
p.t.Logf("error: "+msg, args...)
|
||||
}
|
||||
|
||||
func (p *TestPrinter) S(msg string, args ...interface{}) {
|
||||
p.t.Logf("stdout: "+msg, args...)
|
||||
}
|
||||
|
||||
func (p *TestPrinter) P(msg string, args ...interface{}) {
|
||||
p.t.Logf("print: "+msg, args...)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue