mirror of
https://github.com/restic/restic.git
synced 2026-08-05 21:33:16 +00:00
restic: move Printer interface from internal/ui/progress
Move Printer and NewNoopPrinter to internal/restic so repository does not have to import the ui packages.
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// jsonProgress reports progress for the `backup` command in JSON.
|
||||
type jsonProgress struct {
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
|
||||
term ui.Terminal
|
||||
v uint
|
||||
|
||||
@@ -21,7 +21,7 @@ type ProgressPrinter interface {
|
||||
Finish(snapshotID restic.ID, summary *archiver.Summary, dryRun bool)
|
||||
Reset()
|
||||
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
}
|
||||
|
||||
type Counter struct {
|
||||
|
||||
@@ -8,12 +8,11 @@ import (
|
||||
"github.com/restic/restic/internal/archiver"
|
||||
"github.com/restic/restic/internal/data"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
)
|
||||
|
||||
type mockPrinter struct {
|
||||
sync.Mutex
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
dirUnchanged, fileNew bool
|
||||
id restic.ID
|
||||
}
|
||||
@@ -48,7 +47,7 @@ func (p *mockPrinter) Reset() {}
|
||||
func TestProgress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prnt := &mockPrinter{Printer: progress.NewNoopPrinter()}
|
||||
prnt := &mockPrinter{Printer: restic.NewNoopPrinter()}
|
||||
prog := newProgress(prnt, time.Millisecond)
|
||||
|
||||
prog.StartFile("foo")
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// textProgress reports progress for the `backup` command.
|
||||
type textProgress struct {
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
|
||||
term ui.Terminal
|
||||
verbosity uint
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package progress
|
||||
|
||||
import (
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
// A Printer can can return a new counter or print messages
|
||||
// at different log levels.
|
||||
// It must be safe to call its methods from concurrent goroutines.
|
||||
type Printer interface {
|
||||
// NewCounter returns a new progress counter. It is not shown if --quiet or --json is specified.
|
||||
NewCounter(description string) restic.Counter
|
||||
// NewCounterTerminalOnly returns a new progress counter that is only shown if stdout points to a
|
||||
// terminal. It is not shown if --quiet or --json is specified.
|
||||
NewCounterTerminalOnly(description string) restic.Counter
|
||||
|
||||
// E reports an error. This message is always printed to stderr.
|
||||
// Appends a newline if not present.
|
||||
E(msg string, args ...interface{})
|
||||
// S prints a message, this is should only be used for very important messages
|
||||
// that are not errors. The message is even printed if --quiet is specified.
|
||||
// Appends a newline if not present.
|
||||
S(msg string, args ...interface{})
|
||||
// PT prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified)
|
||||
// and stdout points to a terminal.
|
||||
// This is used for informational messages.
|
||||
PT(msg string, args ...interface{})
|
||||
// P prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified),
|
||||
// this is used for normal messages which are not errors. Appends a newline if not present.
|
||||
P(msg string, args ...interface{})
|
||||
// V prints a message if verbosity >= 2 (equivalent to --verbose), this is used for
|
||||
// verbose messages. Appends a newline if not present.
|
||||
V(msg string, args ...interface{})
|
||||
// VV prints a message if verbosity >= 3 (equivalent to --verbose=2), this is used for
|
||||
// debug messages. Appends a newline if not present.
|
||||
VV(msg string, args ...interface{})
|
||||
}
|
||||
|
||||
// noopPrinter discards all messages.
|
||||
type noopPrinter struct{}
|
||||
|
||||
var _ Printer = (*noopPrinter)(nil)
|
||||
|
||||
// NewNoopPrinter returns a Printer that discards all messages.
|
||||
func NewNoopPrinter() Printer {
|
||||
return &noopPrinter{}
|
||||
}
|
||||
|
||||
func (*noopPrinter) NewCounter(_ string) restic.Counter {
|
||||
return restic.NoopCounter
|
||||
}
|
||||
|
||||
func (*noopPrinter) NewCounterTerminalOnly(_ string) restic.Counter {
|
||||
return restic.NoopCounter
|
||||
}
|
||||
|
||||
func (*noopPrinter) E(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*noopPrinter) S(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*noopPrinter) PT(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*noopPrinter) P(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*noopPrinter) V(_ string, _ ...interface{}) {}
|
||||
|
||||
func (*noopPrinter) VV(_ string, _ ...interface{}) {}
|
||||
@@ -98,7 +98,7 @@ func (t *terminalPrinter) VV(msg string, args ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewTerminalPrinter(json bool, verbosity uint, term ui.Terminal) Printer {
|
||||
func NewTerminalPrinter(json bool, verbosity uint, term ui.Terminal) restic.Printer {
|
||||
if json {
|
||||
verbosity = 0
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package restore
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
)
|
||||
|
||||
type jsonPrinter struct {
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
|
||||
terminal ui.Terminal
|
||||
verbosity uint
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
)
|
||||
|
||||
@@ -38,7 +39,7 @@ type ProgressPrinter interface {
|
||||
Error(item string, err error) error
|
||||
CompleteItem(action ItemAction, item string, size uint64)
|
||||
Finish(progress State, duration time.Duration)
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
}
|
||||
|
||||
type ItemAction string
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package restore
|
||||
|
||||
import (
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -37,7 +38,7 @@ type mockPrinter struct {
|
||||
trace printerTrace
|
||||
items itemTrace
|
||||
errors errorTrace
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
}
|
||||
|
||||
const mockFinishDuration = 42 * time.Second
|
||||
@@ -57,7 +58,7 @@ func (p *mockPrinter) Finish(progress State, _ time.Duration) {
|
||||
}
|
||||
|
||||
func testProgress(fn func(progress *Progress) bool) (printerTrace, itemTrace, errorTrace) {
|
||||
printer := &mockPrinter{Printer: progress.NewNoopPrinter()}
|
||||
printer := &mockPrinter{Printer: restic.NewNoopPrinter()}
|
||||
progress := newProgress(printer, 0)
|
||||
final := fn(progress)
|
||||
progress.update(0, final)
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
)
|
||||
|
||||
type textPrinter struct {
|
||||
progress.Printer
|
||||
restic.Printer
|
||||
|
||||
terminal ui.Terminal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user