list: convert to termstatus

This commit is contained in:
Michael Eischer
2025-09-14 10:36:31 +02:00
parent 0226e46681
commit 333dbd18d8
2 changed files with 15 additions and 7 deletions

View File

@@ -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
})
}

View File

@@ -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)