diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index e0f901738..e4de65752 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -29,6 +29,7 @@ import ( "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/textfile" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/ui/backup" ) @@ -534,7 +535,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te defer unlock() progressReporter := backup.NewProgress(printer, - ui.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) + progress.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) defer progressReporter.Done() // rejectByNameFuncs collect functions that can reject items from the backup based on path only diff --git a/cmd/restic/cmd_cache.go b/cmd/restic/cmd_cache.go index 7a571ae85..5c61ab115 100644 --- a/cmd/restic/cmd_cache.go +++ b/cmd/restic/cmd_cache.go @@ -12,6 +12,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/ui/table" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -57,7 +58,7 @@ func (opts *CacheOptions) AddFlags(f *pflag.FlagSet) { } func runCache(opts CacheOptions, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) if len(args) > 0 { return errors.Fatal("the cache command expects no arguments, only options - please see `restic help cache` for usage and flags") diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 0d64dbd87..437c4437b 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -13,6 +13,7 @@ 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" ) var catAllowedCmds = []string{"config", "index", "snapshot", "key", "masterkey", "lock", "pack", "blob", "tree"} @@ -67,7 +68,7 @@ func validateCatArgs(args []string) error { } func runCat(ctx context.Context, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) if err := validateCatArgs(args); err != nil { return err diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 4a5a54694..83d673193 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -231,7 +231,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts global.Options, args var printer progress.Printer if !gopts.JSON { - printer = ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer = progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) } else { printer = newJSONErrorPrinter(term) } diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index d17ded7c9..7728af1a2 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -106,7 +106,7 @@ func collectAllSnapshots(ctx context.Context, opts CopyOptions, } func runCopy(ctx context.Context, opts CopyOptions, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) secondaryGopts, isFromRepo, err := opts.SecondaryRepoOptions.FillGlobalOpts(ctx, gopts, "destination") if err != nil { return err diff --git a/cmd/restic/cmd_copy_integration_test.go b/cmd/restic/cmd_copy_integration_test.go index 252b2fdfe..29e269578 100644 --- a/cmd/restic/cmd_copy_integration_test.go +++ b/cmd/restic/cmd_copy_integration_test.go @@ -9,7 +9,7 @@ import ( "github.com/restic/restic/internal/global" "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" ) func testRunCopy(t testing.TB, srcGopts global.Options, dstGopts global.Options) { @@ -97,7 +97,7 @@ func TestCopy(t *testing.T) { func testPackAndBlobCounts(t testing.TB, gopts global.Options) (countTreePacks int, countDataPacks int, countBlobs int) { rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index efc022941..a92160d26 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -17,6 +17,7 @@ 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" ) func registerDebugCommand(cmd *cobra.Command, globalOptions *global.Options) { @@ -117,7 +118,7 @@ func debugPrintSnapshots(ctx context.Context, repo *repository.Repository, wr io } func runDebugDump(ctx context.Context, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) if len(args) != 1 { return errors.Fatal("type not specified") @@ -158,7 +159,7 @@ func runDebugDump(ctx context.Context, gopts global.Options, args []string, term } func runDebugExamine(ctx context.Context, gopts global.Options, opts DebugExamineOptions, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) if opts.ExtractPack && gopts.NoLock { return fmt.Errorf("--extract-pack and --no-lock are mutually exclusive") diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index 500e38ff5..883216bbe 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -12,6 +12,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -358,7 +359,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts global.Options, args [ return errors.Fatalf("specify two snapshot IDs") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index 87ca88f2c..981cd95ff 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -14,6 +14,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -136,7 +137,7 @@ func runDump(ctx context.Context, opts DumpOptions, gopts global.Options, args [ return errors.Fatal("no file and no snapshot ID specified") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) switch opts.Archive { case "tar", "zip": diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 5254b58a0..baa47dc1f 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -19,6 +19,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/walker" ) @@ -599,7 +600,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts global.Options, args [ return errors.Fatal("wrong number of arguments") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) var err error pat := findPattern{pattern: args} diff --git a/cmd/restic/cmd_find_integration_test.go b/cmd/restic/cmd_find_integration_test.go index f46d63cc5..e5e35348f 100644 --- a/cmd/restic/cmd_find_integration_test.go +++ b/cmd/restic/cmd_find_integration_test.go @@ -12,7 +12,7 @@ import ( "github.com/restic/restic/internal/global" "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" ) func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts global.Options, pattern string) []byte { @@ -169,7 +169,7 @@ func TestFindPackfile(t *testing.T) { // do all the testing wrapped inside withTermStatus() err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -228,7 +228,7 @@ func TestFindPackID(t *testing.T) { dataPackID := restic.ID{} treePackID := restic.ID{} err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index f1521f1c2..8dabb7feb 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -12,6 +12,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -189,7 +190,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption return errors.Fatal("--no-lock is only applicable in combination with --dry-run for forget command") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer) if err != nil { return err diff --git a/cmd/restic/cmd_generate.go b/cmd/restic/cmd_generate.go index 9f7d5611f..0a491518d 100644 --- a/cmd/restic/cmd_generate.go +++ b/cmd/restic/cmd_generate.go @@ -116,7 +116,7 @@ func runGenerate(opts generateOptions, gopts global.Options, args []string, term return errors.Fatal("the generate command expects no arguments, only options - please see `restic help generate` for usage and flags") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) cmdRoot := newRootCommand(&global.Options{}) if opts.ManDir != "" { diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 50d8810d8..9bf765353 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -60,7 +60,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts global.Options, args [ return errors.Fatal("the init command expects no arguments, only options - please see `restic help init` for usage and flags") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) var version uint switch opts.RepositoryVersion { diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index f83a048ab..c0d156189 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -60,7 +60,7 @@ func runKeyAdd(ctx context.Context, gopts global.Options, opts KeyAddOptions, ar return fmt.Errorf("the key add command expects no arguments, only options - please see `restic help key add` for usage and flags") } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, false, printer) if err != nil { return err diff --git a/cmd/restic/cmd_key_list.go b/cmd/restic/cmd_key_list.go index a7828b44f..77da22e34 100644 --- a/cmd/restic/cmd_key_list.go +++ b/cmd/restic/cmd_key_list.go @@ -46,7 +46,7 @@ func runKeyList(ctx context.Context, gopts global.Options, args []string, term u return fmt.Errorf("the key list command expects no arguments, only options - please see `restic help key list` for usage and flags") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index 2f4a9507f..b46a12db2 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -55,7 +55,7 @@ func runKeyPasswd(ctx context.Context, gopts global.Options, opts KeyPasswdOptio return fmt.Errorf("the key passwd command expects no arguments, only options - please see `restic help key passwd` for usage and flags") } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err diff --git a/cmd/restic/cmd_key_remove.go b/cmd/restic/cmd_key_remove.go index 2d85c0122..03eb8f313 100644 --- a/cmd/restic/cmd_key_remove.go +++ b/cmd/restic/cmd_key_remove.go @@ -43,7 +43,7 @@ func runKeyRemove(ctx context.Context, gopts global.Options, args []string, term return fmt.Errorf("key remove expects one argument as the key id") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 11482fab1..7a8df5aed 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -9,6 +9,7 @@ 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/spf13/cobra" ) @@ -44,7 +45,7 @@ Exit status is 12 if the password is incorrect. } func runList(ctx context.Context, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) if len(args) != 1 { return errors.Fatal("type not specified") diff --git a/cmd/restic/cmd_list_integration_test.go b/cmd/restic/cmd_list_integration_test.go index 655d6da27..6b2358d47 100644 --- a/cmd/restic/cmd_list_integration_test.go +++ b/cmd/restic/cmd_list_integration_test.go @@ -11,7 +11,7 @@ import ( "github.com/restic/restic/internal/global" "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" ) func testRunList(t testing.TB, gopts global.Options, tpe string) restic.IDs { @@ -61,7 +61,7 @@ func testListSnapshots(t testing.TB, gopts global.Options, expected int) restic. // extract blob set from repository index func testListBlobs(t testing.TB, gopts global.Options) (blobSetFromIndex restic.IDSet) { err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 92e3abfcc..9672805f3 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -21,6 +21,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/walker" ) @@ -305,7 +306,7 @@ type toSortOutput struct { } func runLs(ctx context.Context, opts LsOptions, gopts global.Options, args []string, term ui.Terminal) error { - termPrinter := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + termPrinter := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) if len(args) == 0 { return errors.Fatal("no snapshot ID specified, specify snapshot ID or use special ID 'latest'") diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index 8ad3541eb..1832b8b12 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -135,7 +135,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts global.Opti } func runMigrate(ctx context.Context, opts MigrateOptions, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index cb88a70e2..2322e6769 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -21,6 +21,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/fuse" @@ -119,7 +120,7 @@ func (opts *MountOptions) AddFlags(f *pflag.FlagSet) { } func runMount(ctx context.Context, opts MountOptions, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) if opts.TimeTemplate == "" { return errors.Fatal("time template string cannot be empty") diff --git a/cmd/restic/cmd_mount_integration_test.go b/cmd/restic/cmd_mount_integration_test.go index 6f5557778..6aa3b8650 100644 --- a/cmd/restic/cmd_mount_integration_test.go +++ b/cmd/restic/cmd_mount_integration_test.go @@ -18,7 +18,7 @@ import ( "github.com/restic/restic/internal/global" "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" ) const ( @@ -131,7 +131,7 @@ func checkSnapshots(t testing.TB, gopts global.Options, mountpoint string, snaps } err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) if err != nil { return err diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index c0d148990..eab66b839 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -175,7 +175,7 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts global.Options, term return errors.Fatal("--no-lock is only applicable in combination with --dry-run for prune command") } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer) if err != nil { return err diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index bbb71972f..72e8f94f8 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -48,7 +48,7 @@ func runRecover(ctx context.Context, gopts global.Options, term ui.Terminal) err return err } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { return err diff --git a/cmd/restic/cmd_repair_index.go b/cmd/restic/cmd_repair_index.go index 32e38fc7b..de5f43ad6 100644 --- a/cmd/restic/cmd_repair_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -6,6 +6,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -70,7 +71,7 @@ func newRebuildIndexCommand(globalOptions *global.Options) *cobra.Command { } func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts global.Options, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { diff --git a/cmd/restic/cmd_repair_packs.go b/cmd/restic/cmd_repair_packs.go index f0f4cccbf..f32e57706 100644 --- a/cmd/restic/cmd_repair_packs.go +++ b/cmd/restic/cmd_repair_packs.go @@ -11,6 +11,7 @@ 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/spf13/cobra" ) @@ -52,7 +53,7 @@ func runRepairPacks(ctx context.Context, gopts global.Options, term ui.Terminal, return errors.Fatal("no ids specified") } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) if err != nil { diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index b392bf017..b6ffbef8b 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -9,6 +9,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/walker" "github.com/spf13/cobra" @@ -78,7 +79,7 @@ func (opts *RepairOptions) AddFlags(f *pflag.FlagSet) { } func runRepairSnapshots(ctx context.Context, gopts global.Options, opts RepairOptions, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun, printer) if err != nil { diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index d797d1b68..effa27c06 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -167,7 +167,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts global.Options, return err } - progress := restoreui.NewProgress(printer, ui.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) + progress := restoreui.NewProgress(printer, progress.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) res := restorer.NewRestorer(repo, sn, restorer.Options{ DryRun: opts.DryRun, Sparse: opts.Sparse, diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 976fe4f73..1050730d2 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -298,7 +298,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts global.Options, return errors.Fatal("exclude and include patterns are mutually exclusive") } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) var ( repo *repository.Repository diff --git a/cmd/restic/cmd_rewrite_integration_test.go b/cmd/restic/cmd_rewrite_integration_test.go index acef0dd4d..e30f437b2 100644 --- a/cmd/restic/cmd_rewrite_integration_test.go +++ b/cmd/restic/cmd_rewrite_integration_test.go @@ -13,6 +13,7 @@ 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/progress" ) func testRunRewriteExclude(t testing.TB, gopts global.Options, excludes []string, forget bool, metadata snapshotMetadataArgs) { @@ -81,7 +82,7 @@ func getSnapshot(t testing.TB, snapshotID restic.ID, env *testEnvironment) *data var snapshots []*data.Snapshot err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -157,7 +158,7 @@ func testRewriteMetadata(t *testing.T, metadata snapshotMetadataArgs) { var snapshots []*data.Snapshot err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -205,7 +206,7 @@ func TestRewriteSnaphotSummary(t *testing.T) { // replace snapshot by one without a summary var oldSummary *data.SnapshotSummary err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/cmd_self_update.go b/cmd/restic/cmd_self_update.go index 387c9b1d7..946924057 100644 --- a/cmd/restic/cmd_self_update.go +++ b/cmd/restic/cmd_self_update.go @@ -11,6 +11,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/selfupdate" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -84,7 +85,7 @@ func runSelfUpdate(ctx context.Context, opts SelfUpdateOptions, gopts global.Opt } } - printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(false, gopts.Verbosity, term) printer.P("writing restic to %v", opts.Output) v, err := selfupdate.DownloadLatestStableRelease(ctx, opts.Output, global.Version, printer.P) diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 5f938fbe8..12fbc7bf6 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -13,6 +13,7 @@ import ( "github.com/restic/restic/internal/global" "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/spf13/cobra" "github.com/spf13/pflag" @@ -71,7 +72,7 @@ func (opts *SnapshotOptions) AddFlags(f *pflag.FlagSet) { } func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts global.Options, args []string, term ui.Terminal) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { return err diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index d09f97ecb..14424fdcc 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -104,7 +104,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts global.Options, args return err } - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer) if err != nil { @@ -143,7 +143,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts global.Options, args statsProgress := newStatsProgress(term, !gopts.JSON, uint64(len(snapshots))) - updater := progress.NewUpdater(ui.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus()), func(runtime time.Duration, final bool) { + updater := progress.NewUpdater(progress.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus()), func(runtime time.Duration, final bool) { statsProgress.printProgress(runtime, final) }) diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index 6b1503f96..bda249f25 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -13,6 +13,7 @@ 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" ) func newTagCommand(globalOptions *global.Options) *cobra.Command { @@ -120,7 +121,7 @@ func changeTags(ctx context.Context, repo *repository.Repository, sn *data.Snaps } func runTag(ctx context.Context, opts TagOptions, gopts global.Options, term ui.Terminal, args []string) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) if len(opts.SetTags) == 0 && len(opts.AddTags) == 0 && len(opts.RemoveTags) == 0 { return errors.Fatal("nothing to do!") diff --git a/cmd/restic/cmd_unlock.go b/cmd/restic/cmd_unlock.go index 48f2e593d..55452b9fc 100644 --- a/cmd/restic/cmd_unlock.go +++ b/cmd/restic/cmd_unlock.go @@ -6,6 +6,7 @@ import ( "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -47,7 +48,7 @@ func (opts *UnlockOptions) AddFlags(f *pflag.FlagSet) { } func runUnlock(ctx context.Context, opts UnlockOptions, gopts global.Options, term ui.Terminal) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, term) repo, err := global.OpenRepository(ctx, gopts, printer) if err != nil { return err diff --git a/cmd/restic/cmd_version.go b/cmd/restic/cmd_version.go index 1232ea779..a43fe1d0f 100644 --- a/cmd/restic/cmd_version.go +++ b/cmd/restic/cmd_version.go @@ -5,7 +5,7 @@ import ( "runtime" "github.com/restic/restic/internal/global" - "github.com/restic/restic/internal/ui" + "github.com/restic/restic/internal/ui/progress" "github.com/spf13/cobra" ) @@ -25,7 +25,7 @@ Exit status is 1 if there was any error. `, DisableAutoGenTag: true, Run: func(_ *cobra.Command, _ []string) { - printer := ui.NewProgressPrinter(globalOptions.JSON, globalOptions.Verbosity, globalOptions.Term) + printer := progress.NewTerminalPrinter(globalOptions.JSON, globalOptions.Verbosity, globalOptions.Term) if globalOptions.JSON { type jsonVersion struct { diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index f574dbb13..d64447f7d 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -22,7 +22,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/progress" "github.com/restic/restic/internal/ui/termstatus" ) @@ -243,7 +243,7 @@ func testSetupBackupData(t testing.TB, env *testEnvironment) string { func listPacks(gopts global.Options, t *testing.T) restic.IDSet { var packs restic.IDSet err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, r, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -262,7 +262,7 @@ func listPacks(gopts global.Options, t *testing.T) restic.IDSet { func listTreePacks(gopts global.Options, t *testing.T) restic.IDSet { var treePacks restic.IDSet err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, r, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -293,7 +293,7 @@ func captureBackend(gopts *global.Options) func() backend.Backend { func removePacks(gopts global.Options, t testing.TB, remove restic.IDSet) { be := captureBackend(&gopts) err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, _, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -309,7 +309,7 @@ func removePacks(gopts global.Options, t testing.TB, remove restic.IDSet) { func removePacksExcept(gopts global.Options, t testing.TB, keep restic.IDSet, removeTreePacks bool) { be := captureBackend(&gopts) err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, r, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() @@ -370,7 +370,7 @@ func lastSnapshot(old, new map[string]struct{}) (map[string]struct{}, string) { func testLoadSnapshot(t testing.TB, gopts global.Options, id restic.ID) *data.Snapshot { var snapshot *data.Snapshot err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) _, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 8c7ac6ccd..de3000527 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -14,7 +14,7 @@ import ( "github.com/restic/restic/internal/global" "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" ) func TestCheckRestoreNoLock(t *testing.T) { @@ -165,7 +165,7 @@ func TestFindListOnce(t *testing.T) { var snapshotIDs restic.IDSet rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error { - printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) + printer := progress.NewTerminalPrinter(gopts.JSON, gopts.Verbosity, gopts.Term) ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer) rtest.OK(t, err) defer unlock() diff --git a/internal/ui/backup/json.go b/internal/ui/backup/json.go index a678045ac..de91eff50 100644 --- a/internal/ui/backup/json.go +++ b/internal/ui/backup/json.go @@ -24,7 +24,7 @@ var _ ProgressPrinter = &jsonProgress{} // NewJSONProgress returns a new backup progress reporter. func NewJSONProgress(term ui.Terminal, verbosity uint) ProgressPrinter { return &jsonProgress{ - Printer: ui.NewProgressPrinter(true, verbosity, term), + Printer: progress.NewTerminalPrinter(true, verbosity, term), term: term, v: verbosity, } diff --git a/internal/ui/backup/text.go b/internal/ui/backup/text.go index 0a0ccdbea..b402e211a 100644 --- a/internal/ui/backup/text.go +++ b/internal/ui/backup/text.go @@ -25,7 +25,7 @@ var _ ProgressPrinter = &textProgress{} // NewTextProgress returns a new backup progress reporter. func NewTextProgress(term ui.Terminal, verbosity uint) ProgressPrinter { return &textProgress{ - Printer: ui.NewProgressPrinter(false, verbosity, term), + Printer: progress.NewTerminalPrinter(false, verbosity, term), term: term, verbosity: verbosity, } diff --git a/internal/ui/progress.go b/internal/ui/progress/terminal.go similarity index 64% rename from internal/ui/progress.go rename to internal/ui/progress/terminal.go index 4a9b432e7..9b0ab111e 100644 --- a/internal/ui/progress.go +++ b/internal/ui/progress/terminal.go @@ -1,4 +1,4 @@ -package ui +package progress import ( "fmt" @@ -6,7 +6,7 @@ import ( "strconv" "time" - "github.com/restic/restic/internal/ui/progress" + "github.com/restic/restic/internal/ui" ) // CalculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS @@ -27,20 +27,20 @@ func CalculateProgressInterval(show bool, json bool, canUpdateStatus bool) time. } // newProgressMax returns a progress.Counter that prints to terminal if provided. -func newProgressMax(show bool, max uint64, description string, term Terminal) *progress.Counter { +func newProgressMax(show bool, max uint64, description string, term ui.Terminal) *Counter { if !show { return nil } interval := CalculateProgressInterval(show, false, term.CanUpdateStatus()) - return progress.NewCounter(interval, max, func(v uint64, max uint64, d time.Duration, final bool) { + return NewCounter(interval, max, func(v uint64, max uint64, d time.Duration, final bool) { var status string if max == 0 { status = fmt.Sprintf("[%s] %d %s", - FormatDuration(d), v, description) + ui.FormatDuration(d), v, description) } else { status = fmt.Sprintf("[%s] %s %d / %d %s", - FormatDuration(d), FormatPercent(v, max), v, max, description) + ui.FormatDuration(d), ui.FormatPercent(v, max), v, max, description) } if final { @@ -52,56 +52,56 @@ func newProgressMax(show bool, max uint64, description string, term Terminal) *p }) } -type progressPrinter struct { - term Terminal +type terminalPrinter struct { + term ui.Terminal v uint } -func (t *progressPrinter) NewCounter(description string) *progress.Counter { +func (t *terminalPrinter) NewCounter(description string) *Counter { return newProgressMax(t.v > 0, 0, description, t.term) } -func (t *progressPrinter) NewCounterTerminalOnly(description string) *progress.Counter { +func (t *terminalPrinter) NewCounterTerminalOnly(description string) *Counter { return newProgressMax(t.v > 0 && t.term.OutputIsTerminal(), 0, description, t.term) } -func (t *progressPrinter) E(msg string, args ...interface{}) { +func (t *terminalPrinter) E(msg string, args ...interface{}) { t.term.Error(fmt.Sprintf(msg, args...)) } -func (t *progressPrinter) S(msg string, args ...interface{}) { +func (t *terminalPrinter) S(msg string, args ...interface{}) { t.term.Print(fmt.Sprintf(msg, args...)) } -func (t *progressPrinter) PT(msg string, args ...interface{}) { +func (t *terminalPrinter) PT(msg string, args ...interface{}) { if t.term.OutputIsTerminal() && t.v >= 1 { t.term.Print(fmt.Sprintf(msg, args...)) } } -func (t *progressPrinter) P(msg string, args ...interface{}) { +func (t *terminalPrinter) P(msg string, args ...interface{}) { if t.v >= 1 { t.term.Print(fmt.Sprintf(msg, args...)) } } -func (t *progressPrinter) V(msg string, args ...interface{}) { +func (t *terminalPrinter) V(msg string, args ...interface{}) { if t.v >= 2 { t.term.Print(fmt.Sprintf(msg, args...)) } } -func (t *progressPrinter) VV(msg string, args ...interface{}) { +func (t *terminalPrinter) VV(msg string, args ...interface{}) { if t.v >= 3 { t.term.Print(fmt.Sprintf(msg, args...)) } } -func NewProgressPrinter(json bool, verbosity uint, term Terminal) progress.Printer { +func NewTerminalPrinter(json bool, verbosity uint, term ui.Terminal) Printer { if json { verbosity = 0 } - return &progressPrinter{ + return &terminalPrinter{ term: term, v: verbosity, } diff --git a/internal/ui/restore/json.go b/internal/ui/restore/json.go index 8e6e3cfd4..86fc492d4 100644 --- a/internal/ui/restore/json.go +++ b/internal/ui/restore/json.go @@ -16,7 +16,7 @@ type jsonPrinter struct { func NewJSONProgress(terminal ui.Terminal, verbosity uint) ProgressPrinter { return &jsonPrinter{ - Printer: ui.NewProgressPrinter(true, verbosity, terminal), + Printer: progress.NewTerminalPrinter(true, verbosity, terminal), terminal: terminal, verbosity: verbosity, } diff --git a/internal/ui/restore/text.go b/internal/ui/restore/text.go index 464615ecb..5eee78bfd 100644 --- a/internal/ui/restore/text.go +++ b/internal/ui/restore/text.go @@ -16,7 +16,7 @@ type textPrinter struct { func NewTextProgress(terminal ui.Terminal, verbosity uint) ProgressPrinter { return &textPrinter{ - Printer: ui.NewProgressPrinter(false, verbosity, terminal), + Printer: progress.NewTerminalPrinter(false, verbosity, terminal), terminal: terminal, } }