restore: print JSON versions of errors in --json mode

Previously, they were printed as freeform text.

This also adds a ui.Terminal interface to make writing
tests easier and also adds a few tests.
This commit is contained in:
Michael Terry 2024-07-27 19:06:26 -04:00
parent ad2585af67
commit a376323331
17 changed files with 234 additions and 70 deletions

View file

@ -32,13 +32,9 @@ type progressInfoEntry struct {
bytesTotal uint64
}
type term interface {
Print(line string)
SetStatus(lines []string)
}
type ProgressPrinter interface {
Update(progress State, duration time.Duration)
Error(item string, err error) error
CompleteItem(action ItemAction, item string, size uint64)
Finish(progress State, duration time.Duration)
}
@ -139,6 +135,17 @@ func (p *Progress) ReportDeletedFile(name string) {
p.printer.CompleteItem(ActionDeleted, name, 0)
}
func (p *Progress) Error(item string, err error) error {
if p == nil {
return nil
}
p.m.Lock()
defer p.m.Unlock()
return p.printer.Error(item, err)
}
func (p *Progress) Finish() {
p.updater.Done()
}