mirror of
https://github.com/restic/restic.git
synced 2025-12-13 12:52:34 +00:00
list: convert to termstatus
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/repository/index"
|
"github.com/restic/restic/internal/repository/index"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
|
"github.com/restic/restic/internal/ui/termstatus"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -33,7 +34,9 @@ Exit status is 12 if the password is incorrect.
|
|||||||
DisableAutoGenTag: true,
|
DisableAutoGenTag: true,
|
||||||
GroupID: cmdGroupDefault,
|
GroupID: cmdGroupDefault,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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,
|
ValidArgs: listAllowedArgs,
|
||||||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
@@ -41,7 +44,9 @@ Exit status is 12 if the password is incorrect.
|
|||||||
return cmd
|
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 {
|
if len(args) != 1 {
|
||||||
return errors.Fatal("type not specified")
|
return errors.Fatal("type not specified")
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,7 @@ func runList(ctx context.Context, gopts GlobalOptions, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return idx.Each(ctx, func(blobs restic.PackedBlob) {
|
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:
|
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 {
|
return repo.List(ctx, t, func(id restic.ID, _ int64) error {
|
||||||
Printf("%s\n", id)
|
printer.S("%s", id)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
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 {
|
func testRunList(t testing.TB, opts GlobalOptions, tpe string) restic.IDs {
|
||||||
buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error {
|
buf, err := withCaptureStdout(opts, func(opts GlobalOptions) error {
|
||||||
return runList(context.TODO(), gopts, []string{tpe})
|
return withTermStatus(opts, func(ctx context.Context, term *termstatus.Terminal) error {
|
||||||
|
return runList(ctx, opts, []string{tpe}, term)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
return parseIDsFromReader(t, buf)
|
return parseIDsFromReader(t, buf)
|
||||||
|
|||||||
Reference in New Issue
Block a user