From 6b5c8ce14e307404c480ec60a92def3d3d615788 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 15 Sep 2025 21:16:55 +0200 Subject: [PATCH] change run* functions to accept ui.Terminal instead of *termstatus.Terminal --- cmd/restic/cmd_backup.go | 3 +-- cmd/restic/cmd_backup_integration_test.go | 4 ++-- cmd/restic/cmd_cache.go | 3 +-- cmd/restic/cmd_cat.go | 4 ++-- cmd/restic/cmd_check.go | 3 +-- cmd/restic/cmd_check_integration_test.go | 4 ++-- cmd/restic/cmd_copy.go | 4 ++-- cmd/restic/cmd_copy_integration_test.go | 4 ++-- cmd/restic/cmd_debug.go | 6 +++--- cmd/restic/cmd_diff.go | 3 +-- cmd/restic/cmd_diff_integration_test.go | 4 ++-- cmd/restic/cmd_dump.go | 4 ++-- cmd/restic/cmd_find.go | 4 ++-- cmd/restic/cmd_find_integration_test.go | 4 ++-- cmd/restic/cmd_forget.go | 4 ++-- cmd/restic/cmd_forget_integration_test.go | 4 ++-- cmd/restic/cmd_generate.go | 4 ++-- cmd/restic/cmd_generate_integration_test.go | 4 ++-- cmd/restic/cmd_init.go | 4 ++-- cmd/restic/cmd_init_integration_test.go | 8 ++++---- cmd/restic/cmd_key_add.go | 4 ++-- cmd/restic/cmd_key_integration_test.go | 4 ++-- cmd/restic/cmd_key_list.go | 4 ++-- cmd/restic/cmd_key_passwd.go | 4 ++-- cmd/restic/cmd_key_remove.go | 4 ++-- cmd/restic/cmd_list.go | 4 ++-- cmd/restic/cmd_list_integration_test.go | 4 ++-- cmd/restic/cmd_ls.go | 4 ++-- cmd/restic/cmd_ls_integration_test.go | 4 ++-- cmd/restic/cmd_migrate.go | 6 +++--- cmd/restic/cmd_mount.go | 4 ++-- cmd/restic/cmd_mount_integration_test.go | 4 ++-- cmd/restic/cmd_prune.go | 3 +-- cmd/restic/cmd_prune_integration_test.go | 14 +++++++------- cmd/restic/cmd_recover.go | 4 ++-- cmd/restic/cmd_recover_integration_test.go | 6 +++--- cmd/restic/cmd_repair_index.go | 4 ++-- cmd/restic/cmd_repair_index_integration_test.go | 6 +++--- cmd/restic/cmd_repair_packs.go | 4 ++-- cmd/restic/cmd_repair_snapshots.go | 4 ++-- .../cmd_repair_snapshots_integration_test.go | 4 ++-- cmd/restic/cmd_restore.go | 4 ++-- cmd/restic/cmd_restore_integration_test.go | 4 ++-- cmd/restic/cmd_rewrite.go | 4 ++-- cmd/restic/cmd_rewrite_integration_test.go | 7 +++---- cmd/restic/cmd_self_update.go | 4 ++-- cmd/restic/cmd_snapshots.go | 3 +-- cmd/restic/cmd_stats.go | 3 +-- cmd/restic/cmd_tag.go | 3 +-- cmd/restic/cmd_unlock.go | 4 ++-- cmd/restic/integration_helpers_test.go | 3 ++- cmd/restic/integration_test.go | 8 ++++---- cmd/restic/progress.go | 7 +++---- 53 files changed, 113 insertions(+), 122 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index cbd2a6861..e1c516a53 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -29,7 +29,6 @@ import ( "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/backup" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) func newBackupCommand() *cobra.Command { @@ -478,7 +477,7 @@ func findParentSnapshot(ctx context.Context, repo restic.ListerLoaderUnpacked, o return sn, err } -func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, term *termstatus.Terminal, args []string) error { +func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, term ui.Terminal, args []string) error { var vsscfg fs.VSSConfig var err error diff --git a/cmd/restic/cmd_backup_integration_test.go b/cmd/restic/cmd_backup_integration_test.go index c0b6adbdf..ba9ea2e62 100644 --- a/cmd/restic/cmd_backup_integration_test.go +++ b/cmd/restic/cmd_backup_integration_test.go @@ -13,11 +13,11 @@ import ( "github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts BackupOptions, gopts GlobalOptions) error { - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { t.Logf("backing up %v in %v", target, dir) if dir != "" { cleanup := rtest.Chdir(t, dir) diff --git a/cmd/restic/cmd_cache.go b/cmd/restic/cmd_cache.go index 2ab116427..efc632b07 100644 --- a/cmd/restic/cmd_cache.go +++ b/cmd/restic/cmd_cache.go @@ -12,7 +12,6 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/table" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -58,7 +57,7 @@ func (opts *CacheOptions) AddFlags(f *pflag.FlagSet) { f.BoolVar(&opts.NoSize, "no-size", false, "do not output the size of the cache directories") } -func runCache(opts CacheOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runCache(opts CacheOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if len(args) > 0 { diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 44049c86a..41ea9f5e0 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -10,7 +10,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) var catAllowedCmds = []string{"config", "index", "snapshot", "key", "masterkey", "lock", "pack", "blob", "tree"} @@ -66,7 +66,7 @@ func validateCatArgs(args []string) error { return nil } -func runCat(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runCat(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if err := validateCatArgs(args); err != nil { diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index a251d96bf..8b9937b69 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -20,7 +20,6 @@ import ( "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) func newCheckCommand() *cobra.Command { @@ -220,7 +219,7 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions, printer progress return cleanup } -func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) (checkSummary, error) { +func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args []string, term ui.Terminal) (checkSummary, error) { summary := checkSummary{MessageType: "summary"} if len(args) != 0 { return summary, errors.Fatal("the check command expects no arguments, only options - please see `restic help check` for usage and flags") diff --git a/cmd/restic/cmd_check_integration_test.go b/cmd/restic/cmd_check_integration_test.go index f5a3dc395..59a0f7498 100644 --- a/cmd/restic/cmd_check_integration_test.go +++ b/cmd/restic/cmd_check_integration_test.go @@ -6,7 +6,7 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunCheck(t testing.TB, gopts GlobalOptions) { @@ -27,7 +27,7 @@ func testRunCheckMustFail(t testing.TB, gopts GlobalOptions) { func testRunCheckOutput(gopts GlobalOptions, checkUnused bool) (string, error) { buf := bytes.NewBuffer(nil) gopts.stdout = buf - err := withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + err := withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { opts := CheckOptions{ ReadData: true, CheckUnused: checkUnused, diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index e216d8258..004a223ce 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -8,8 +8,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "golang.org/x/sync/errgroup" "github.com/spf13/cobra" @@ -69,7 +69,7 @@ func (opts *CopyOptions) AddFlags(f *pflag.FlagSet) { initMultiSnapshotFilter(f, &opts.SnapshotFilter, true) } -func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) secondaryGopts, isFromRepo, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "destination", printer) if err != nil { diff --git a/cmd/restic/cmd_copy_integration_test.go b/cmd/restic/cmd_copy_integration_test.go index 83cfb8425..2dc27050f 100644 --- a/cmd/restic/cmd_copy_integration_test.go +++ b/cmd/restic/cmd_copy_integration_test.go @@ -7,7 +7,7 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunCopy(t testing.TB, srcGopts GlobalOptions, dstGopts GlobalOptions) { @@ -23,7 +23,7 @@ func testRunCopy(t testing.TB, srcGopts GlobalOptions, dstGopts GlobalOptions) { }, } - rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runCopy(context.TODO(), copyOpts, gopts, nil, term) })) } diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index b3e3aac30..8498224c8 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -27,8 +27,8 @@ import ( "github.com/restic/restic/internal/repository/index" "github.com/restic/restic/internal/repository/pack" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) func registerDebugCommand(cmd *cobra.Command) { @@ -187,7 +187,7 @@ func dumpIndexes(ctx context.Context, repo restic.ListerLoaderUnpacked, wr io.Wr }) } -func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if len(args) != 1 { @@ -458,7 +458,7 @@ func storePlainBlob(id restic.ID, prefix string, plain []byte, printer progress. return nil } -func runDebugExamine(ctx context.Context, gopts GlobalOptions, opts DebugExamineOptions, args []string, term *termstatus.Terminal) error { +func runDebugExamine(ctx context.Context, gopts GlobalOptions, opts DebugExamineOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if opts.ExtractPack && gopts.NoLock { diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index d3c0c4cd6..8560a35c8 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -11,7 +11,6 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -363,7 +362,7 @@ func (c *Comparer) diffTree(ctx context.Context, stats *DiffStatsContainer, pref return ctx.Err() } -func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) != 2 { return errors.Fatalf("specify two snapshot IDs") } diff --git a/cmd/restic/cmd_diff_integration_test.go b/cmd/restic/cmd_diff_integration_test.go index e3525f52f..ee20671c4 100644 --- a/cmd/restic/cmd_diff_integration_test.go +++ b/cmd/restic/cmd_diff_integration_test.go @@ -12,7 +12,7 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapshotID string) (string, error) { @@ -20,7 +20,7 @@ func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapsh opts := DiffOptions{ ShowMetadata: false, } - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runDiff(ctx, opts, gopts, []string{firstSnapshotID, secondSnapshotID}, term) }) }) diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index 336d37648..6a2a2cce8 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -12,7 +12,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/terminal" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -128,7 +128,7 @@ func printFromTree(ctx context.Context, tree *restic.Tree, repo restic.BlobLoade return fmt.Errorf("path %q not found in snapshot", item) } -func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) != 2 { return errors.Fatal("no file and no snapshot ID specified") } diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index b97465e7d..705d12648 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -16,7 +16,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/filter" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/walker" ) @@ -579,7 +579,7 @@ func (f *Finder) findObjectsPacks() { } } -func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) == 0 { return errors.Fatal("wrong number of arguments") } diff --git a/cmd/restic/cmd_find_integration_test.go b/cmd/restic/cmd_find_integration_test.go index 65b153405..ad34923ed 100644 --- a/cmd/restic/cmd_find_integration_test.go +++ b/cmd/restic/cmd_find_integration_test.go @@ -8,14 +8,14 @@ import ( "time" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts GlobalOptions, pattern string) []byte { buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.JSON = wantJSON - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runFind(ctx, opts, gopts, []string{pattern}, term) }) }) diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index b7f66278e..850417c9c 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -9,7 +9,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -173,7 +173,7 @@ func verifyForgetOptions(opts *ForgetOptions) error { return nil } -func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOptions, gopts GlobalOptions, term *termstatus.Terminal, args []string) error { +func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOptions, gopts GlobalOptions, term ui.Terminal, args []string) error { err := verifyForgetOptions(&opts) if err != nil { return err diff --git a/cmd/restic/cmd_forget_integration_test.go b/cmd/restic/cmd_forget_integration_test.go index 96dd7c63e..d3be8a60d 100644 --- a/cmd/restic/cmd_forget_integration_test.go +++ b/cmd/restic/cmd_forget_integration_test.go @@ -8,14 +8,14 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunForgetMayFail(gopts GlobalOptions, opts ForgetOptions, args ...string) error { pruneOpts := PruneOptions{ MaxUnused: "5%", } - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runForget(context.TODO(), opts, pruneOpts, gopts, term, args) }) } diff --git a/cmd/restic/cmd_generate.go b/cmd/restic/cmd_generate.go index b1dfcee5d..cf7b3c1ea 100644 --- a/cmd/restic/cmd_generate.go +++ b/cmd/restic/cmd_generate.go @@ -7,8 +7,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/terminal" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "github.com/spf13/pflag" @@ -115,7 +115,7 @@ func checkStdoutForSingleShell(opts generateOptions) error { return nil } -func runGenerate(opts generateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runGenerate(opts generateOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) > 0 { return errors.Fatal("the generate command expects no arguments, only options - please see `restic help generate` for usage and flags") } diff --git a/cmd/restic/cmd_generate_integration_test.go b/cmd/restic/cmd_generate_integration_test.go index 0a5d4361a..858e72453 100644 --- a/cmd/restic/cmd_generate_integration_test.go +++ b/cmd/restic/cmd_generate_integration_test.go @@ -6,12 +6,12 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunGenerate(gopts GlobalOptions, opts generateOptions) ([]byte, error) { buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runGenerate(opts, gopts, []string{}, term) }) }) diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 9fabaf5d4..c11015feb 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -10,8 +10,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -57,7 +57,7 @@ func (opts *InitOptions) AddFlags(f *pflag.FlagSet) { f.StringVar(&opts.RepositoryVersion, "repository-version", "stable", "repository format version to use, allowed values are a format version, 'latest' and 'stable'") } -func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) > 0 { return errors.Fatal("the init command expects no arguments, only options - please see `restic help init` for usage and flags") } diff --git a/cmd/restic/cmd_init_integration_test.go b/cmd/restic/cmd_init_integration_test.go index 245ad1003..8ce14a23a 100644 --- a/cmd/restic/cmd_init_integration_test.go +++ b/cmd/restic/cmd_init_integration_test.go @@ -9,8 +9,8 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) func testRunInit(t testing.TB, opts GlobalOptions) { @@ -18,7 +18,7 @@ func testRunInit(t testing.TB, opts GlobalOptions) { restic.TestDisableCheckPolynomial(t) restic.TestSetLockTimeout(t, 0) - err := withTermStatus(opts, func(ctx context.Context, term *termstatus.Terminal) error { + err := withTermStatus(opts, func(ctx context.Context, term ui.Terminal) error { return runInit(ctx, InitOptions{}, opts, nil, term) }) rtest.OK(t, err) @@ -44,13 +44,13 @@ func TestInitCopyChunkerParams(t *testing.T) { password: env2.gopts.password, }, } - err := withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + err := withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runInit(ctx, initOpts, env.gopts, nil, term) }) rtest.Assert(t, err != nil, "expected invalid init options to fail") initOpts.CopyChunkerParameters = true - err = withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + err = withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runInit(ctx, initOpts, env.gopts, nil, term) }) rtest.OK(t, err) diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index 6842c154d..00343e17a 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -6,8 +6,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -56,7 +56,7 @@ func (opts *KeyAddOptions) Add(flags *pflag.FlagSet) { flags.StringVarP(&opts.Hostname, "host", "", "", "the hostname for new key") } -func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, args []string, term *termstatus.Terminal) error { +func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, args []string, term ui.Terminal) error { if len(args) > 0 { return fmt.Errorf("the key add command expects no arguments, only options - please see `restic help key add` for usage and flags") } diff --git a/cmd/restic/cmd_key_integration_test.go b/cmd/restic/cmd_key_integration_test.go index 76ed214c9..a02e58c09 100644 --- a/cmd/restic/cmd_key_integration_test.go +++ b/cmd/restic/cmd_key_integration_test.go @@ -12,13 +12,13 @@ import ( "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/repository" rtest "github.com/restic/restic/internal/test" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string { buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runKeyList(ctx, gopts, []string{}, term) }) }) diff --git a/cmd/restic/cmd_key_list.go b/cmd/restic/cmd_key_list.go index f24e2af32..897601675 100644 --- a/cmd/restic/cmd_key_list.go +++ b/cmd/restic/cmd_key_list.go @@ -8,9 +8,9 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/ui/table" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ Exit status is 12 if the password is incorrect. return cmd } -func runKeyList(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runKeyList(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) > 0 { return fmt.Errorf("the key list command expects no arguments, only options - please see `restic help key list` for usage and flags") } diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index 7ccbc9903..b472d4da9 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -6,8 +6,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,7 +51,7 @@ func (opts *KeyPasswdOptions) AddFlags(flags *pflag.FlagSet) { opts.KeyAddOptions.Add(flags) } -func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOptions, args []string, term *termstatus.Terminal) error { +func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOptions, args []string, term ui.Terminal) error { if len(args) > 0 { return fmt.Errorf("the key passwd command expects no arguments, only options - please see `restic help key passwd` for usage and flags") } diff --git a/cmd/restic/cmd_key_remove.go b/cmd/restic/cmd_key_remove.go index 94db263ee..e8d69074c 100644 --- a/cmd/restic/cmd_key_remove.go +++ b/cmd/restic/cmd_key_remove.go @@ -7,8 +7,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" ) @@ -39,7 +39,7 @@ Exit status is 12 if the password is incorrect. return cmd } -func runKeyRemove(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runKeyRemove(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error { if len(args) != 1 { return fmt.Errorf("key remove expects one argument as the key id") } diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 993c77dba..3e8068901 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -7,7 +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/restic/restic/internal/ui" "github.com/spf13/cobra" ) @@ -44,7 +44,7 @@ Exit status is 12 if the password is incorrect. return cmd } -func runList(ctx context.Context, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runList(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if len(args) != 1 { diff --git a/cmd/restic/cmd_list_integration_test.go b/cmd/restic/cmd_list_integration_test.go index 95b1fab8f..69fef1d6b 100644 --- a/cmd/restic/cmd_list_integration_test.go +++ b/cmd/restic/cmd_list_integration_test.go @@ -8,12 +8,12 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) 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 withTermStatus(opts, func(ctx context.Context, term ui.Terminal) error { return runList(ctx, opts, []string{tpe}, term) }) }) diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index c5e7e485c..532d2f4dd 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -18,7 +18,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/walker" ) @@ -303,7 +303,7 @@ type toSortOutput struct { node *restic.Node } -func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { termPrinter := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if len(args) == 0 { diff --git a/cmd/restic/cmd_ls_integration_test.go b/cmd/restic/cmd_ls_integration_test.go index 11787f5cb..b39e9e582 100644 --- a/cmd/restic/cmd_ls_integration_test.go +++ b/cmd/restic/cmd_ls_integration_test.go @@ -10,13 +10,13 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunLsWithOpts(t testing.TB, gopts GlobalOptions, opts LsOptions, args []string) []byte { buf, err := withCaptureStdout(gopts, func(gopts GlobalOptions) error { gopts.Quiet = true - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runLs(context.TODO(), opts, gopts, args, term) }) }) diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index 1960135af..87f2e429a 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -5,8 +5,8 @@ import ( "github.com/restic/restic/internal/migrations" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -77,7 +77,7 @@ func checkMigrations(ctx context.Context, repo restic.Repository, printer progre return nil } -func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string, term *termstatus.Terminal, printer progress.Printer) error { +func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, repo restic.Repository, args []string, term ui.Terminal, printer progress.Printer) error { var firsterr error for _, name := range args { found := false @@ -135,7 +135,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptio return firsterr } -func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 85f6c6410..b85e1be5f 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -16,7 +16,7 @@ import ( "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/fuse" @@ -115,7 +115,7 @@ func (opts *MountOptions) AddFlags(f *pflag.FlagSet) { _ = f.MarkDeprecated("snapshot-template", "use --time-template") } -func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if opts.TimeTemplate == "" { diff --git a/cmd/restic/cmd_mount_integration_test.go b/cmd/restic/cmd_mount_integration_test.go index 4fbf42694..e38ea4e49 100644 --- a/cmd/restic/cmd_mount_integration_test.go +++ b/cmd/restic/cmd_mount_integration_test.go @@ -16,7 +16,7 @@ import ( "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) const ( @@ -62,7 +62,7 @@ func testRunMount(t testing.TB, gopts GlobalOptions, dir string, wg *sync.WaitGr opts := MountOptions{ TimeTemplate: time.RFC3339, } - rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runMount(context.TODO(), opts, gopts, []string{dir}, term) })) } diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 0b0d94440..64ffeea3a 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -13,7 +13,6 @@ import ( "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -155,7 +154,7 @@ func verifyPruneOptions(opts *PruneOptions) error { return nil } -func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term *termstatus.Terminal) error { +func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term ui.Terminal) error { err := verifyPruneOptions(&opts) if err != nil { return err diff --git a/cmd/restic/cmd_prune_integration_test.go b/cmd/restic/cmd_prune_integration_test.go index 007304921..d9103fc8f 100644 --- a/cmd/restic/cmd_prune_integration_test.go +++ b/cmd/restic/cmd_prune_integration_test.go @@ -9,7 +9,7 @@ import ( "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/repository" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunPrune(t testing.TB, gopts GlobalOptions, opts PruneOptions) { @@ -29,7 +29,7 @@ func testRunPruneOutput(gopts GlobalOptions, opts PruneOptions) error { defer func() { gopts.backendTestHook = oldHook }() - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runPrune(context.TODO(), opts, gopts, term) }) } @@ -99,7 +99,7 @@ func testRunForgetJSON(t testing.TB, gopts GlobalOptions, args ...string) { pruneOpts := PruneOptions{ MaxUnused: "5%", } - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runForget(context.TODO(), opts, pruneOpts, gopts, term, args) }) }) @@ -122,7 +122,7 @@ func testPrune(t *testing.T, pruneOpts PruneOptions, checkOpts CheckOptions) { createPrunableRepo(t, env) testRunPrune(t, env.gopts, pruneOpts) - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { _, err := runCheck(context.TODO(), checkOpts, env.gopts, nil, term) return err })) @@ -158,7 +158,7 @@ func TestPruneWithDamagedRepository(t *testing.T) { env.gopts.backendTestHook = oldHook }() // prune should fail - rtest.Equals(t, repository.ErrPacksMissing, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.Equals(t, repository.ErrPacksMissing, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runPrune(context.TODO(), pruneDefaultOptions, env.gopts, term) }), "prune should have reported index not complete error") } @@ -231,7 +231,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o if checkOK { testRunCheck(t, env.gopts) } else { - rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { _, err := runCheck(context.TODO(), optionsCheck, env.gopts, nil, term) return err }) != nil, @@ -242,7 +242,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o testRunPrune(t, env.gopts, optionsPrune) testRunCheck(t, env.gopts) } else { - rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.Assert(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runPrune(context.TODO(), optionsPrune, env.gopts, term) }) != nil, "prune should have reported an error") diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index 60a3d445f..9d9b96d68 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -8,8 +8,8 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" ) @@ -43,7 +43,7 @@ Exit status is 12 if the password is incorrect. return cmd } -func runRecover(ctx context.Context, gopts GlobalOptions, term *termstatus.Terminal) error { +func runRecover(ctx context.Context, gopts GlobalOptions, term ui.Terminal) error { hostname, err := os.Hostname() if err != nil { return err diff --git a/cmd/restic/cmd_recover_integration_test.go b/cmd/restic/cmd_recover_integration_test.go index 121575fdb..91dec1505 100644 --- a/cmd/restic/cmd_recover_integration_test.go +++ b/cmd/restic/cmd_recover_integration_test.go @@ -5,11 +5,11 @@ import ( "testing" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunRecover(t testing.TB, gopts GlobalOptions) { - rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runRecover(context.TODO(), gopts, term) })) } @@ -33,7 +33,7 @@ func TestRecover(t *testing.T) { ids = testListSnapshots(t, env.gopts, 1) testRunCheck(t, env.gopts) // check that the root tree is included in the snapshot - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runCat(context.TODO(), env.gopts, []string{"tree", ids[0].String() + ":" + sn.Tree.Str()}, term) })) } diff --git a/cmd/restic/cmd_repair_index.go b/cmd/restic/cmd_repair_index.go index e8bb31fca..924574031 100644 --- a/cmd/restic/cmd_repair_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -4,7 +4,7 @@ import ( "context" "github.com/restic/restic/internal/repository" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -72,7 +72,7 @@ func newRebuildIndexCommand() *cobra.Command { return cmd } -func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, term *termstatus.Terminal) error { +func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) diff --git a/cmd/restic/cmd_repair_index_integration_test.go b/cmd/restic/cmd_repair_index_integration_test.go index 2b76bf4b3..6d1e81eee 100644 --- a/cmd/restic/cmd_repair_index_integration_test.go +++ b/cmd/restic/cmd_repair_index_integration_test.go @@ -13,12 +13,12 @@ import ( "github.com/restic/restic/internal/repository/index" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) { rtest.OK(t, withRestoreGlobalOptions(func() error { - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { globalOptions.stdout = io.Discard return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, term) }) @@ -132,7 +132,7 @@ func TestRebuildIndexFailsOnAppendOnly(t *testing.T) { env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) { return &appendOnlyBackend{r}, nil } - return withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { globalOptions.stdout = io.Discard return runRebuildIndex(context.TODO(), RepairIndexOptions{}, env.gopts, term) }) diff --git a/cmd/restic/cmd_repair_packs.go b/cmd/restic/cmd_repair_packs.go index 4c2177647..c2f3c55d0 100644 --- a/cmd/restic/cmd_repair_packs.go +++ b/cmd/restic/cmd_repair_packs.go @@ -9,7 +9,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" ) @@ -40,7 +40,7 @@ Exit status is 12 if the password is incorrect. return cmd } -func runRepairPacks(ctx context.Context, gopts GlobalOptions, term *termstatus.Terminal, args []string) error { +func runRepairPacks(ctx context.Context, gopts GlobalOptions, term ui.Terminal, args []string) error { ids := restic.NewIDSet() for _, arg := range args { id, err := restic.ParseID(arg) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 09c0bfa79..ff53e72b5 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -5,7 +5,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/walker" "github.com/spf13/cobra" @@ -75,7 +75,7 @@ func (opts *RepairOptions) AddFlags(f *pflag.FlagSet) { initMultiSnapshotFilter(f, &opts.SnapshotFilter, true) } -func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOptions, args []string, term *termstatus.Terminal) error { +func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun, printer) diff --git a/cmd/restic/cmd_repair_snapshots_integration_test.go b/cmd/restic/cmd_repair_snapshots_integration_test.go index d6bf055a5..6594d211c 100644 --- a/cmd/restic/cmd_repair_snapshots_integration_test.go +++ b/cmd/restic/cmd_repair_snapshots_integration_test.go @@ -12,7 +12,7 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunRepairSnapshot(t testing.TB, gopts GlobalOptions, forget bool) { @@ -20,7 +20,7 @@ func testRunRepairSnapshot(t testing.TB, gopts GlobalOptions, forget bool) { Forget: forget, } - rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runRepairSnapshots(context.TODO(), gopts, opts, nil, term) })) } diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index f28406be4..915829b0c 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -10,9 +10,9 @@ import ( "github.com/restic/restic/internal/filter" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restorer" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" restoreui "github.com/restic/restic/internal/ui/restore" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -89,7 +89,7 @@ func (opts *RestoreOptions) AddFlags(f *pflag.FlagSet) { } func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, - term *termstatus.Terminal, args []string) error { + term ui.Terminal, args []string) error { msg := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) excludePatternFns, err := opts.ExcludePatternOptions.CollectPatterns(msg.E) diff --git a/cmd/restic/cmd_restore_integration_test.go b/cmd/restic/cmd_restore_integration_test.go index 945c24a37..9746b28af 100644 --- a/cmd/restic/cmd_restore_integration_test.go +++ b/cmd/restic/cmd_restore_integration_test.go @@ -14,7 +14,7 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func testRunRestore(t testing.TB, opts GlobalOptions, dir string, snapshotID string) { @@ -31,7 +31,7 @@ func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snaps } func testRunRestoreAssumeFailure(snapshotID string, opts RestoreOptions, gopts GlobalOptions) error { - return withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + return withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runRestore(ctx, opts, gopts, term, []string{snapshotID}) }) } diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 0e06e4009..eb9f6b7ec 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -13,8 +13,8 @@ import ( "github.com/restic/restic/internal/filter" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" "github.com/restic/restic/internal/walker" ) @@ -291,7 +291,7 @@ func filterAndReplaceSnapshot(ctx context.Context, repo restic.Repository, sn *r return true, nil } -func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if !opts.SnapshotSummary && opts.ExcludePatternOptions.Empty() && opts.Metadata.empty() { return errors.Fatal("Nothing to do: no excludes provided and no new metadata provided") } diff --git a/cmd/restic/cmd_rewrite_integration_test.go b/cmd/restic/cmd_rewrite_integration_test.go index 57b223591..5a748823d 100644 --- a/cmd/restic/cmd_rewrite_integration_test.go +++ b/cmd/restic/cmd_rewrite_integration_test.go @@ -9,7 +9,6 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/ui" - "github.com/restic/restic/internal/ui/termstatus" ) func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string, forget bool, metadata snapshotMetadataArgs) { @@ -21,7 +20,7 @@ func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string, Metadata: metadata, } - rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(gopts, func(ctx context.Context, term ui.Terminal) error { return runRewrite(context.TODO(), opts, gopts, nil, term) })) } @@ -154,7 +153,7 @@ func TestRewriteSnaphotSummary(t *testing.T) { defer cleanup() createBasicRewriteRepo(t, env) - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, env.gopts, []string{}, term) })) // no new snapshot should be created as the snapshot already has a summary @@ -176,7 +175,7 @@ func TestRewriteSnaphotSummary(t *testing.T) { unlock() // rewrite snapshot and lookup ID of new snapshot - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, env.gopts, []string{}, term) })) newSnapshots := testListSnapshots(t, env.gopts, 2) diff --git a/cmd/restic/cmd_self_update.go b/cmd/restic/cmd_self_update.go index 7b2dff5e2..167229040 100644 --- a/cmd/restic/cmd_self_update.go +++ b/cmd/restic/cmd_self_update.go @@ -9,7 +9,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/selfupdate" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -62,7 +62,7 @@ func (opts *SelfUpdateOptions) AddFlags(f *pflag.FlagSet) { f.StringVar(&opts.Output, "output", "", "Save the downloaded file as `filename` (default: running binary itself)") } -func runSelfUpdate(ctx context.Context, opts SelfUpdateOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runSelfUpdate(ctx context.Context, opts SelfUpdateOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { if opts.Output == "" { file, err := os.Executable() if err != nil { diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 8cd663e06..99c00f68a 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -11,7 +11,6 @@ import ( "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/table" - "github.com/restic/restic/internal/ui/termstatus" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -69,7 +68,7 @@ func (opts *SnapshotOptions) AddFlags(f *pflag.FlagSet) { f.VarP(&opts.GroupBy, "group-by", "g", "`group` snapshots by host, paths and/or tags, separated by comma") } -func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 411ac9e31..00f885ffa 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -16,7 +16,6 @@ import ( "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/ui/table" - "github.com/restic/restic/internal/ui/termstatus" "github.com/restic/restic/internal/walker" "github.com/spf13/cobra" @@ -96,7 +95,7 @@ func must(err error) { } } -func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args []string, term *termstatus.Terminal) error { +func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args []string, term ui.Terminal) error { err := verifyStatsInput(opts) if err != nil { return err diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index 5d1f19a63..fde4209bc 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -11,7 +11,6 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" - "github.com/restic/restic/internal/ui/termstatus" ) func newTagCommand() *cobra.Command { @@ -119,7 +118,7 @@ func changeTags(ctx context.Context, repo *repository.Repository, sn *restic.Sna return changed, nil } -func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term *termstatus.Terminal, args []string) error { +func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term ui.Terminal, args []string) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) if len(opts.SetTags) == 0 && len(opts.AddTags) == 0 && len(opts.RemoveTags) == 0 { diff --git a/cmd/restic/cmd_unlock.go b/cmd/restic/cmd_unlock.go index 49e802c1f..8cea239c6 100644 --- a/cmd/restic/cmd_unlock.go +++ b/cmd/restic/cmd_unlock.go @@ -4,7 +4,7 @@ import ( "context" "github.com/restic/restic/internal/repository" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -45,7 +45,7 @@ func (opts *UnlockOptions) AddFlags(f *pflag.FlagSet) { f.BoolVar(&opts.RemoveAll, "remove-all", false, "remove all locks, even non-stale ones") } -func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions, term *termstatus.Terminal) error { +func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions, term ui.Terminal) error { printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term) repo, err := OpenRepository(ctx, gopts, printer) if err != nil { diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 233316c59..fa9e5e50d 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -20,6 +20,7 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" + "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/termstatus" ) @@ -432,7 +433,7 @@ func withCaptureStdout(gopts GlobalOptions, inner func(gopts GlobalOptions) erro return buf, err } -func withTermStatus(gopts GlobalOptions, callback func(ctx context.Context, term *termstatus.Terminal) error) error { +func withTermStatus(gopts GlobalOptions, callback func(ctx context.Context, term ui.Terminal) error) error { ctx, cancel := context.WithCancel(context.TODO()) var wg sync.WaitGroup diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 3b2f53d38..e51275966 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -12,7 +12,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" - "github.com/restic/restic/internal/ui/termstatus" + "github.com/restic/restic/internal/ui" ) func TestCheckRestoreNoLock(t *testing.T) { @@ -87,14 +87,14 @@ func TestListOnce(t *testing.T) { createPrunableRepo(t, env) testRunPrune(t, env.gopts, pruneOpts) - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { _, err := runCheck(context.TODO(), checkOpts, env.gopts, nil, term) return err })) - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runRebuildIndex(context.TODO(), RepairIndexOptions{}, env.gopts, term) })) - rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term *termstatus.Terminal) error { + rtest.OK(t, withTermStatus(env.gopts, func(ctx context.Context, term ui.Terminal) error { return runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, env.gopts, term) })) } diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index caf34e50b..37ba0e623 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -9,7 +9,6 @@ import ( "github.com/restic/restic/internal/terminal" "github.com/restic/restic/internal/ui" "github.com/restic/restic/internal/ui/progress" - "github.com/restic/restic/internal/ui/termstatus" ) // calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS @@ -30,7 +29,7 @@ func calculateProgressInterval(show bool, json bool) time.Duration { } // newTerminalProgressMax returns a progress.Counter that prints to terminal if provided. -func newTerminalProgressMax(show bool, max uint64, description string, term *termstatus.Terminal) *progress.Counter { +func newTerminalProgressMax(show bool, max uint64, description string, term ui.Terminal) *progress.Counter { if !show { return nil } @@ -56,7 +55,7 @@ func newTerminalProgressMax(show bool, max uint64, description string, term *ter } type terminalProgressPrinter struct { - term *termstatus.Terminal + term ui.Terminal ui.Message show bool } @@ -69,7 +68,7 @@ func (t *terminalProgressPrinter) NewCounterTerminalOnly(description string) *pr return newTerminalProgressMax(t.show && terminal.StdoutIsTerminal(), 0, description, t.term) } -func newTerminalProgressPrinter(json bool, verbosity uint, term *termstatus.Terminal) progress.Printer { +func newTerminalProgressPrinter(json bool, verbosity uint, term ui.Terminal) progress.Printer { if json { verbosity = 0 }