diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index cf0cec414..5500f1932 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -7,6 +7,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository/index" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" ) @@ -33,7 +34,9 @@ Exit status is 12 if the password is incorrect. DisableAutoGenTag: true, GroupID: cmdGroupDefault, RunE: func(cmd *cobra.Command, args []string) error { - return runList(cmd.Context(), globalOptions, args) + term, cancel := setupTermstatus() + defer cancel() + return runList(cmd.Context(), globalOptions, args, term) }, ValidArgs: listAllowedArgs, Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), @@ -41,7 +44,9 @@ Exit status is 12 if the password is incorrect. return cmd } -func runList(ctx context.Context, gopts GlobalOptions, args []string) error { +func runList(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { + printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) + if len(args) != 1 { return errors.Fatal("type not specified") } @@ -70,7 +75,7 @@ func runList(ctx context.Context, gopts GlobalOptions, args []string) error { return err } return idx.Each(ctx, func(blobs restic.PackedBlob) { - Printf("%v %v\n", blobs.Type, blobs.ID) + printer.S("%v %v", blobs.Type, blobs.ID) }) }) default: @@ -78,7 +83,7 @@ func runList(ctx context.Context, gopts GlobalOptions, args []string) error { } return repo.List(ctx, t, func(id restic.ID, _ int64) error { - Printf("%s\n", id) + printer.S("%s", id) return nil }) } diff --git a/cmd/restic/cmd_list_integration_test.go b/cmd/restic/cmd_list_integration_test.go index 6a32b763b..95b1fab8f 100644 --- a/cmd/restic/cmd_list_integration_test.go +++ b/cmd/restic/cmd_list_integration_test.go @@ -8,11 +8,14 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" + "github.com/restic/restic/internal/ui/termstatus" ) -func testRunList(t testing.TB, gopts GlobalOptions, tpe string) restic.IDs { - buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { - return runList(context.TODO(), gopts, []string{tpe}) +func testRunList(t testing.TB, opts GlobalOptions, tpe string) restic.IDs { + buf, err := withCaptureStdout(opts, func(opts GlobalOptions) error { + return withTermStatus(opts, func(ctx context.Context, term *termstatus.Terminal) error { + return runList(ctx, opts, []string{tpe}, term) + }) }) rtest.OK(t, err) return parseIDsFromReader(t, buf)