From 44dbd4469e4952c3e41e6297647f9e758de4c761 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Sep 2025 10:42:02 +0200 Subject: [PATCH] tag: replace global print functions with termstatus --- cmd/restic/cmd_tag.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index 39e9a16b5..efae969b9 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -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 {