unlock: convert to termstatus

This commit is contained in:
Michael Eischer
2025-09-14 10:54:56 +02:00
parent 902cd1e9d6
commit d89535634d

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/ui/termstatus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@@ -26,7 +27,9 @@ Exit status is 1 if there was any error.
GroupID: cmdGroupDefault, GroupID: cmdGroupDefault,
DisableAutoGenTag: true, DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, _ []string) error { RunE: func(cmd *cobra.Command, _ []string) error {
return runUnlock(cmd.Context(), opts, globalOptions) term, cancel := setupTermstatus()
defer cancel()
return runUnlock(cmd.Context(), opts, globalOptions, term)
}, },
} }
opts.AddFlags(cmd.Flags()) opts.AddFlags(cmd.Flags())
@@ -42,7 +45,8 @@ func (opts *UnlockOptions) AddFlags(f *pflag.FlagSet) {
f.BoolVar(&opts.RemoveAll, "remove-all", false, "remove all locks, even non-stale ones") f.BoolVar(&opts.RemoveAll, "remove-all", false, "remove all locks, even non-stale ones")
} }
func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions) error { func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions, term *termstatus.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
repo, err := OpenRepository(ctx, gopts) repo, err := OpenRepository(ctx, gopts)
if err != nil { if err != nil {
return err return err
@@ -59,7 +63,7 @@ func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions) err
} }
if processed > 0 { if processed > 0 {
Verbosef("successfully removed %d locks\n", processed) printer.P("successfully removed %d locks", processed)
} }
return nil return nil
} }