mirror of
https://github.com/restic/restic.git
synced 2026-02-03 12:29:37 -05:00
tag: replace global print functions with termstatus
This commit is contained in:
parent
d8f3e35730
commit
44dbd4469e
1 changed files with 7 additions and 5 deletions
|
|
@ -120,6 +120,8 @@ func changeTags(ctx context.Context, repo *repository.Repository, sn *restic.Sna
|
|||
}
|
||||
|
||||
func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *termstatus.Terminal, args []string) error {
|
||||
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
|
||||
if len(opts.SetTags) == 0 && len(opts.AddTags) == 0 && len(opts.RemoveTags) == 0 {
|
||||
return errors.Fatal("nothing to do!")
|
||||
}
|
||||
|
|
@ -127,7 +129,7 @@ func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *ter
|
|||
return errors.Fatal("--set and --add/--remove cannot be given at the same time")
|
||||
}
|
||||
|
||||
Verbosef("create exclusive lock for repository\n")
|
||||
printer.P("create exclusive lock for repository")
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -135,15 +137,15 @@ func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *ter
|
|||
defer unlock()
|
||||
|
||||
printFunc := func(c changedSnapshot) {
|
||||
Verboseff("old snapshot ID: %v -> new snapshot ID: %v\n", c.OldSnapshotID, c.NewSnapshotID)
|
||||
printer.V("old snapshot ID: %v -> new snapshot ID: %v", c.OldSnapshotID, c.NewSnapshotID)
|
||||
}
|
||||
|
||||
summary := changedSnapshotsSummary{MessageType: "summary", ChangedSnapshots: 0}
|
||||
printSummary := func(c changedSnapshotsSummary) {
|
||||
if c.ChangedSnapshots == 0 {
|
||||
Verbosef("no snapshots were modified\n")
|
||||
printer.P("no snapshots were modified")
|
||||
} else {
|
||||
Verbosef("modified %v snapshots\n", c.ChangedSnapshots)
|
||||
printer.P("modified %v snapshots", c.ChangedSnapshots)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +161,7 @@ func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *ter
|
|||
for sn := range FindFilteredSnapshots(ctx, repo, repo, &opts.SnapshotFilter, args) {
|
||||
changed, err := changeTags(ctx, repo, sn, opts.SetTags.Flatten(), opts.AddTags.Flatten(), opts.RemoveTags.Flatten(), printFunc)
|
||||
if err != nil {
|
||||
Warnf("unable to modify the tags for snapshot ID %q, ignoring: %v\n", sn.ID(), err)
|
||||
printer.E("unable to modify the tags for snapshot ID %q, ignoring: %v", sn.ID(), err)
|
||||
continue
|
||||
}
|
||||
if changed {
|
||||
|
|
|
|||
Loading…
Reference in a new issue