mirror of
https://github.com/restic/restic.git
synced 2025-12-15 21:32:47 +00:00
global: make private fields public
This commit is contained in:
@@ -64,7 +64,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runBackup(cmd.Context(), opts, *globalOptions, globalOptions.term, args)
|
||||
return runBackup(cmd.Context(), opts, *globalOptions, globalOptions.Term, args)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func readFilenamesRaw(r io.Reader) (names []string, err error) {
|
||||
|
||||
// Check returns an error when an invalid combination of options was set.
|
||||
func (opts BackupOptions) Check(gopts GlobalOptions, args []string) error {
|
||||
if gopts.password == "" && !gopts.InsecureNoPassword {
|
||||
if gopts.Password == "" && !gopts.InsecureNoPassword {
|
||||
if opts.Stdin {
|
||||
return errors.Fatal("cannot read both password and data from stdin")
|
||||
}
|
||||
@@ -481,12 +481,12 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||
|
||||
var printer backup.ProgressPrinter
|
||||
if gopts.JSON {
|
||||
printer = backup.NewJSONProgress(term, gopts.verbosity)
|
||||
printer = backup.NewJSONProgress(term, gopts.Verbosity)
|
||||
} else {
|
||||
printer = backup.NewTextProgress(term, gopts.verbosity)
|
||||
printer = backup.NewTextProgress(term, gopts.Verbosity)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
if vsscfg, err = fs.ParseVSSConfig(gopts.extended); err != nil {
|
||||
if vsscfg, err = fs.ParseVSSConfig(gopts.Extended); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -515,7 +515,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||
}
|
||||
}
|
||||
|
||||
if gopts.verbosity >= 2 && !gopts.JSON {
|
||||
if gopts.Verbosity >= 2 && !gopts.JSON {
|
||||
printer.P("open repository")
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts
|
||||
}
|
||||
|
||||
opts.GroupBy = data.SnapshotGroupByOptions{Host: true, Path: true}
|
||||
return runBackup(ctx, opts, gopts, gopts.term, target)
|
||||
return runBackup(ctx, opts, gopts, gopts.Term, target)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -706,7 +706,7 @@ func TestBackupEmptyPassword(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
env.gopts.password = ""
|
||||
env.gopts.Password = ""
|
||||
env.gopts.InsecureNoPassword = true
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
|
||||
@@ -34,7 +34,7 @@ Exit status is 1 if there was any error.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
return runCache(opts, *globalOptions, args, globalOptions.term)
|
||||
return runCache(opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (opts *CacheOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runCache(opts CacheOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(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")
|
||||
@@ -161,7 +161,7 @@ func runCache(opts CacheOptions, gopts GlobalOptions, args []string, term ui.Ter
|
||||
})
|
||||
}
|
||||
|
||||
_ = tab.Write(gopts.term.OutputWriter())
|
||||
_ = tab.Write(gopts.Term.OutputWriter())
|
||||
printer.S("%d cache dirs in %s", len(dirs), cachedir)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -35,7 +35,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runCat(cmd.Context(), *globalOptions, args, globalOptions.term)
|
||||
return runCat(cmd.Context(), *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
ValidArgs: catAllowedCmds,
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func validateCatArgs(args []string) error {
|
||||
}
|
||||
|
||||
func runCat(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
if err := validateCatArgs(args); err != nil {
|
||||
return err
|
||||
|
||||
@@ -46,12 +46,12 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
summary, err := runCheck(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
summary, err := runCheck(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
if globalOptions.JSON {
|
||||
if err != nil && summary.NumErrors == 0 {
|
||||
summary.NumErrors = 1
|
||||
}
|
||||
globalOptions.term.Print(ui.ToJSONString(summary))
|
||||
globalOptions.Term.Print(ui.ToJSONString(summary))
|
||||
}
|
||||
return err
|
||||
},
|
||||
@@ -225,7 +225,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
|
||||
|
||||
var printer progress.Printer
|
||||
if !gopts.JSON {
|
||||
printer = ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer = ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
} else {
|
||||
printer = newJSONErrorPrinter(term)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func testRunCheckOutput(t testing.TB, gopts GlobalOptions, checkUnused bool) (st
|
||||
ReadData: true,
|
||||
CheckUnused: checkUnused,
|
||||
}
|
||||
_, err := runCheck(context.TODO(), opts, gopts, nil, gopts.term)
|
||||
_, err := runCheck(context.TODO(), opts, gopts, nil, gopts.Term)
|
||||
return err
|
||||
})
|
||||
return buf.String(), err
|
||||
|
||||
@@ -50,7 +50,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runCopy(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runCopy(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (opts *CopyOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
secondaryGopts, isFromRepo, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "destination")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -12,18 +12,18 @@ import (
|
||||
func testRunCopy(t testing.TB, srcGopts GlobalOptions, dstGopts GlobalOptions) {
|
||||
gopts := srcGopts
|
||||
gopts.Repo = dstGopts.Repo
|
||||
gopts.password = dstGopts.password
|
||||
gopts.Password = dstGopts.Password
|
||||
gopts.InsecureNoPassword = dstGopts.InsecureNoPassword
|
||||
copyOpts := CopyOptions{
|
||||
secondaryRepoOptions: secondaryRepoOptions{
|
||||
Repo: srcGopts.Repo,
|
||||
password: srcGopts.password,
|
||||
password: srcGopts.Password,
|
||||
InsecureNoPassword: srcGopts.InsecureNoPassword,
|
||||
},
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runCopy(context.TODO(), copyOpts, gopts, nil, gopts.term)
|
||||
return runCopy(context.TODO(), copyOpts, gopts, nil, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func TestCopyToEmptyPassword(t *testing.T) {
|
||||
defer cleanup()
|
||||
env2, cleanup2 := withTestEnvironment(t)
|
||||
defer cleanup2()
|
||||
env2.gopts.password = ""
|
||||
env2.gopts.Password = ""
|
||||
env2.gopts.InsecureNoPassword = true
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
|
||||
@@ -69,7 +69,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDebugDump(cmd.Context(), *globalOptions, args, globalOptions.term)
|
||||
return runDebugDump(cmd.Context(), *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@@ -83,7 +83,7 @@ func newDebugExamineCommand(globalOptions *GlobalOptions) *cobra.Command {
|
||||
Short: "Examine a pack file",
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDebugExamine(cmd.Context(), *globalOptions, opts, args, globalOptions.term)
|
||||
return runDebugExamine(cmd.Context(), *globalOptions, opts, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func dumpIndexes(ctx context.Context, repo restic.ListerLoaderUnpacked, wr io.Wr
|
||||
}
|
||||
|
||||
func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
if len(args) != 1 {
|
||||
return errors.Fatal("type not specified")
|
||||
@@ -201,20 +201,20 @@ func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term
|
||||
|
||||
switch tpe {
|
||||
case "indexes":
|
||||
return dumpIndexes(ctx, repo, gopts.term.OutputWriter(), printer)
|
||||
return dumpIndexes(ctx, repo, gopts.Term.OutputWriter(), printer)
|
||||
case "snapshots":
|
||||
return debugPrintSnapshots(ctx, repo, gopts.term.OutputWriter())
|
||||
return debugPrintSnapshots(ctx, repo, gopts.Term.OutputWriter())
|
||||
case "packs":
|
||||
return printPacks(ctx, repo, gopts.term.OutputWriter(), printer)
|
||||
return printPacks(ctx, repo, gopts.Term.OutputWriter(), printer)
|
||||
case "all":
|
||||
printer.S("snapshots:")
|
||||
err := debugPrintSnapshots(ctx, repo, gopts.term.OutputWriter())
|
||||
err := debugPrintSnapshots(ctx, repo, gopts.Term.OutputWriter())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printer.S("indexes:")
|
||||
err = dumpIndexes(ctx, repo, gopts.term.OutputWriter(), printer)
|
||||
err = dumpIndexes(ctx, repo, gopts.Term.OutputWriter(), printer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func storePlainBlob(id restic.ID, prefix string, plain []byte, printer progress.
|
||||
}
|
||||
|
||||
func runDebugExamine(ctx context.Context, gopts GlobalOptions, opts DebugExamineOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
if opts.ExtractPack && gopts.NoLock {
|
||||
return fmt.Errorf("--extract-pack and --no-lock are mutually exclusive")
|
||||
|
||||
@@ -53,7 +53,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDiff(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runDiff(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []
|
||||
return errors.Fatalf("specify two snapshot IDs")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
@@ -424,7 +424,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []
|
||||
}
|
||||
|
||||
if gopts.JSON {
|
||||
enc := json.NewEncoder(gopts.term.OutputWriter())
|
||||
enc := json.NewEncoder(gopts.Term.OutputWriter())
|
||||
c.printChange = func(change *Change) {
|
||||
err := enc.Encode(change)
|
||||
if err != nil {
|
||||
@@ -458,7 +458,7 @@ func runDiff(ctx context.Context, opts DiffOptions, gopts GlobalOptions, args []
|
||||
updateBlobs(repo, stats.BlobsAfter.Sub(both).Sub(stats.BlobsCommon), &stats.Added, printer.E)
|
||||
|
||||
if gopts.JSON {
|
||||
err := json.NewEncoder(gopts.term.OutputWriter()).Encode(stats)
|
||||
err := json.NewEncoder(gopts.Term.OutputWriter()).Encode(stats)
|
||||
if err != nil {
|
||||
printer.E("JSON encode failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func testRunDiffOutput(t testing.TB, gopts GlobalOptions, firstSnapshotID string
|
||||
opts := DiffOptions{
|
||||
ShowMetadata: false,
|
||||
}
|
||||
return runDiff(ctx, opts, gopts, []string{firstSnapshotID, secondSnapshotID}, gopts.term)
|
||||
return runDiff(ctx, opts, gopts, []string{firstSnapshotID, secondSnapshotID}, gopts.Term)
|
||||
})
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runDump(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runDump(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []
|
||||
return errors.Fatal("no file and no snapshot ID specified")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
switch opts.Archive {
|
||||
case "tar", "zip":
|
||||
|
||||
@@ -37,7 +37,7 @@ Exit status is 1 if there was any error.
|
||||
return errors.Fatal("the feature command expects no arguments")
|
||||
}
|
||||
|
||||
globalOptions.term.Print("All Feature Flags:\n")
|
||||
globalOptions.Term.Print("All Feature Flags:\n")
|
||||
flags := feature.Flag.List()
|
||||
|
||||
tab := table.New()
|
||||
@@ -49,7 +49,7 @@ Exit status is 1 if there was any error.
|
||||
for _, flag := range flags {
|
||||
tab.AddRow(flag)
|
||||
}
|
||||
return tab.Write(globalOptions.term.OutputWriter())
|
||||
return tab.Write(globalOptions.Term.OutputWriter())
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runFind(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runFind(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args []
|
||||
return errors.Fatal("wrong number of arguments")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
var err error
|
||||
pat := findPattern{pattern: args}
|
||||
|
||||
@@ -14,7 +14,7 @@ func testRunFind(t testing.TB, wantJSON bool, opts FindOptions, gopts GlobalOpti
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.JSON = wantJSON
|
||||
|
||||
return runFind(ctx, opts, gopts, []string{pattern}, gopts.term)
|
||||
return runFind(ctx, opts, gopts, []string{pattern}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
return buf.Bytes()
|
||||
|
||||
@@ -51,7 +51,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runForget(cmd.Context(), opts, pruneOpts, *globalOptions, globalOptions.term, args)
|
||||
return runForget(cmd.Context(), opts, pruneOpts, *globalOptions, globalOptions.Term, args)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -188,7 +188,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 := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -253,7 +253,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
||||
}
|
||||
|
||||
if gopts.Verbose >= 1 && !gopts.JSON {
|
||||
err = PrintSnapshotGroupHeader(gopts.term.OutputWriter(), k)
|
||||
err = PrintSnapshotGroupHeader(gopts.Term.OutputWriter(), k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
||||
}
|
||||
if len(keep) != 0 && !gopts.Quiet && !gopts.JSON {
|
||||
printer.P("keep %d snapshots:\n", len(keep))
|
||||
if err := PrintSnapshots(gopts.term.OutputWriter(), keep, reasons, opts.Compact); err != nil {
|
||||
if err := PrintSnapshots(gopts.Term.OutputWriter(), keep, reasons, opts.Compact); err != nil {
|
||||
return err
|
||||
}
|
||||
printer.P("\n")
|
||||
@@ -285,7 +285,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
||||
|
||||
if len(remove) != 0 && !gopts.Quiet && !gopts.JSON {
|
||||
printer.P("remove %d snapshots:\n", len(remove))
|
||||
if err := PrintSnapshots(gopts.term.OutputWriter(), remove, nil, opts.Compact); err != nil {
|
||||
if err := PrintSnapshots(gopts.Term.OutputWriter(), remove, nil, opts.Compact); err != nil {
|
||||
return err
|
||||
}
|
||||
printer.P("\n")
|
||||
@@ -330,7 +330,7 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
||||
}
|
||||
|
||||
if gopts.JSON && len(jsonGroups) > 0 {
|
||||
err = printJSONForget(gopts.term.OutputWriter(), jsonGroups)
|
||||
err = printJSONForget(gopts.Term.OutputWriter(), jsonGroups)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func testRunForgetMayFail(t testing.TB, gopts GlobalOptions, opts ForgetOptions,
|
||||
MaxUnused: "5%",
|
||||
}
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.term, args)
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.Term, args)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Exit status is 1 if there was any error.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
return runGenerate(opts, *globalOptions, args, globalOptions.term)
|
||||
return runGenerate(opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
opts.AddFlags(cmd.Flags())
|
||||
@@ -84,7 +84,7 @@ func writeCompletion(filename string, shell string, generate func(w io.Writer) e
|
||||
defer func() { err = outFile.Close() }()
|
||||
outWriter = outFile
|
||||
} else {
|
||||
outWriter = gopts.term.OutputWriter()
|
||||
outWriter = gopts.Term.OutputWriter()
|
||||
}
|
||||
|
||||
err = generate(outWriter)
|
||||
@@ -115,7 +115,7 @@ func runGenerate(opts generateOptions, gopts GlobalOptions, 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 := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
cmdRoot := newRootCommand(&GlobalOptions{})
|
||||
|
||||
if opts.ManDir != "" {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func testRunGenerate(t testing.TB, gopts GlobalOptions, opts generateOptions) ([]byte, error) {
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runGenerate(opts, gopts, []string{}, gopts.term)
|
||||
return runGenerate(opts, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ Exit status is 1 if there was any error.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runInit(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runInit(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
opts.AddFlags(cmd.Flags())
|
||||
@@ -60,7 +60,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, 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 := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
var version uint
|
||||
switch opts.RepositoryVersion {
|
||||
@@ -90,16 +90,16 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []
|
||||
return err
|
||||
}
|
||||
|
||||
gopts.password, err = ReadPasswordTwice(ctx, gopts,
|
||||
gopts.Password, err = ReadPasswordTwice(ctx, gopts,
|
||||
"enter password for new repository: ",
|
||||
"enter password again: ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
be, err := create(ctx, gopts.Repo, gopts, gopts.extended, printer)
|
||||
be, err := create(ctx, gopts.Repo, gopts, gopts.Extended, printer)
|
||||
if err != nil {
|
||||
return errors.Fatalf("create repository at %s failed: %v", location.StripPassword(gopts.backends, gopts.Repo), err)
|
||||
return errors.Fatalf("create repository at %s failed: %v", location.StripPassword(gopts.Backends, gopts.Repo), err)
|
||||
}
|
||||
|
||||
s, err := repository.New(be, repository.Options{
|
||||
@@ -110,13 +110,13 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []
|
||||
return errors.Fatalf("%s", err)
|
||||
}
|
||||
|
||||
err = s.Init(ctx, version, gopts.password, chunkerPolynomial)
|
||||
err = s.Init(ctx, version, gopts.Password, chunkerPolynomial)
|
||||
if err != nil {
|
||||
return errors.Fatalf("create key in repository at %s failed: %v", location.StripPassword(gopts.backends, gopts.Repo), err)
|
||||
return errors.Fatalf("create key in repository at %s failed: %v", location.StripPassword(gopts.Backends, gopts.Repo), err)
|
||||
}
|
||||
|
||||
if !gopts.JSON {
|
||||
printer.P("created restic repository %v at %s", s.Config().ID[:10], location.StripPassword(gopts.backends, gopts.Repo))
|
||||
printer.P("created restic repository %v at %s", s.Config().ID[:10], location.StripPassword(gopts.Backends, gopts.Repo))
|
||||
if opts.CopyChunkerParameters && chunkerPolynomial != nil {
|
||||
printer.P(" with chunker parameters copied from secondary repository")
|
||||
}
|
||||
@@ -129,9 +129,9 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []
|
||||
status := initSuccess{
|
||||
MessageType: "initialized",
|
||||
ID: s.Config().ID,
|
||||
Repository: location.StripPassword(gopts.backends, gopts.Repo),
|
||||
Repository: location.StripPassword(gopts.Backends, gopts.Repo),
|
||||
}
|
||||
return json.NewEncoder(gopts.term.OutputWriter()).Encode(status)
|
||||
return json.NewEncoder(gopts.Term.OutputWriter()).Encode(status)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -18,7 +18,7 @@ func testRunInit(t testing.TB, gopts GlobalOptions) {
|
||||
restic.TestSetLockTimeout(t, 0)
|
||||
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, InitOptions{}, gopts, nil, gopts.term)
|
||||
return runInit(ctx, InitOptions{}, gopts, nil, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
t.Logf("repository initialized at %v", gopts.Repo)
|
||||
@@ -40,17 +40,17 @@ func TestInitCopyChunkerParams(t *testing.T) {
|
||||
initOpts := InitOptions{
|
||||
secondaryRepoOptions: secondaryRepoOptions{
|
||||
Repo: env2.gopts.Repo,
|
||||
password: env2.gopts.password,
|
||||
password: env2.gopts.Password,
|
||||
},
|
||||
}
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.term)
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.Term)
|
||||
})
|
||||
rtest.Assert(t, err != nil, "expected invalid init options to fail")
|
||||
|
||||
initOpts.CopyChunkerParameters = true
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.term)
|
||||
return runInit(ctx, initOpts, gopts, nil, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runKeyAdd(cmd.Context(), *globalOptions, opts, args, globalOptions.term)
|
||||
return runKeyAdd(cmd.Context(), *globalOptions, opts, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, arg
|
||||
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 := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -119,7 +119,7 @@ func getNewPassword(ctx context.Context, gopts GlobalOptions, newPasswordFile st
|
||||
// Since we already have an open repository, temporary remove the password
|
||||
// to prompt the user for the passwd.
|
||||
newopts := gopts
|
||||
newopts.password = ""
|
||||
newopts.Password = ""
|
||||
// empty passwords are already handled above
|
||||
newopts.InsecureNoPassword = false
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -41,7 +41,7 @@ func testRunKeyAddNewKey(t testing.TB, newPassword string, gopts GlobalOptions)
|
||||
}()
|
||||
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.term)
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func testRunKeyAddNewKeyUserHost(t testing.TB, gopts GlobalOptions) {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
Username: "john",
|
||||
Hostname: "example.com",
|
||||
}, []string{}, gopts.term)
|
||||
}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -80,7 +80,7 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts GlobalOptions) {
|
||||
}()
|
||||
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.term)
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func testRunKeyRemove(t testing.TB, gopts GlobalOptions, IDs []string) {
|
||||
t.Logf("remove %d keys: %q\n", len(IDs), IDs)
|
||||
for _, id := range IDs {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{id}, gopts.term)
|
||||
return runKeyRemove(ctx, gopts, []string{id}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
@@ -103,26 +103,26 @@ func TestKeyAddRemove(t *testing.T) {
|
||||
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
// must list keys more than once
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
defer cleanup()
|
||||
|
||||
testRunInit(t, env.gopts)
|
||||
|
||||
testRunKeyPasswd(t, "geheim2", env.gopts)
|
||||
env.gopts.password = "geheim2"
|
||||
t.Logf("changed password to %q", env.gopts.password)
|
||||
env.gopts.Password = "geheim2"
|
||||
t.Logf("changed password to %q", env.gopts.Password)
|
||||
|
||||
for _, newPassword := range passwordList {
|
||||
testRunKeyAddNewKey(t, newPassword, env.gopts)
|
||||
t.Logf("added new password %q", newPassword)
|
||||
env.gopts.password = newPassword
|
||||
env.gopts.Password = newPassword
|
||||
testRunKeyRemove(t, env.gopts, testRunKeyListOtherIDs(t, env.gopts))
|
||||
}
|
||||
|
||||
env.gopts.password = passwordList[len(passwordList)-1]
|
||||
t.Logf("testing access with last password %q\n", env.gopts.password)
|
||||
env.gopts.Password = passwordList[len(passwordList)-1]
|
||||
t.Logf("testing access with last password %q\n", env.gopts.Password)
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
testRunCheck(t, env.gopts)
|
||||
@@ -139,7 +139,7 @@ func TestKeyAddInvalid(t *testing.T) {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
NewPasswordFile: "some-file",
|
||||
InsecureNoPassword: true,
|
||||
}, []string{}, gopts.term)
|
||||
}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.Assert(t, strings.Contains(err.Error(), "only either"), "unexpected error message, got %q", err)
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestKeyAddInvalid(t *testing.T) {
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
NewPasswordFile: pwfile,
|
||||
}, []string{}, gopts.term)
|
||||
}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.Assert(t, strings.Contains(err.Error(), "an empty password is not allowed by default"), "unexpected error message, got %q", err)
|
||||
}
|
||||
@@ -157,18 +157,18 @@ func TestKeyAddInvalid(t *testing.T) {
|
||||
func TestKeyAddEmpty(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
// must list keys more than once
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
defer cleanup()
|
||||
testRunInit(t, env.gopts)
|
||||
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{
|
||||
InsecureNoPassword: true,
|
||||
}, []string{}, gopts.term)
|
||||
}, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
env.gopts.password = ""
|
||||
env.gopts.Password = ""
|
||||
env.gopts.InsecureNoPassword = true
|
||||
|
||||
testRunCheck(t, env.gopts)
|
||||
@@ -187,7 +187,7 @@ func TestKeyProblems(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
testRunInit(t, env.gopts)
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return &emptySaveBackend{r}, nil
|
||||
}
|
||||
|
||||
@@ -197,20 +197,20 @@ func TestKeyProblems(t *testing.T) {
|
||||
}()
|
||||
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.term)
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil, "expected passwd change to fail")
|
||||
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.term)
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil, "expected key adding to fail")
|
||||
|
||||
t.Logf("testing access with initial password %q\n", env.gopts.password)
|
||||
t.Logf("testing access with initial password %q\n", env.gopts.Password)
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.term)
|
||||
return runKeyList(ctx, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
testRunCheck(t, env.gopts)
|
||||
@@ -221,36 +221,36 @@ func TestKeyCommandInvalidArguments(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
testRunInit(t, env.gopts)
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return &emptySaveBackend{r}, nil
|
||||
}
|
||||
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{"johndoe"}, gopts.term)
|
||||
return runKeyAdd(ctx, gopts, KeyAddOptions{}, []string{"johndoe"}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key add: %v", err)
|
||||
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{"johndoe"}, gopts.term)
|
||||
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{}, []string{"johndoe"}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key passwd: %v", err)
|
||||
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyList(ctx, gopts, []string{"johndoe"}, gopts.term)
|
||||
return runKeyList(ctx, gopts, []string{"johndoe"}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "no arguments"), "unexpected error for key list: %v", err)
|
||||
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{}, gopts.term)
|
||||
return runKeyRemove(ctx, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "one argument"), "unexpected error for key remove: %v", err)
|
||||
|
||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runKeyRemove(ctx, gopts, []string{"john", "doe"}, gopts.term)
|
||||
return runKeyRemove(ctx, gopts, []string{"john", "doe"}, gopts.Term)
|
||||
})
|
||||
t.Log(err)
|
||||
rtest.Assert(t, err != nil && strings.Contains(err.Error(), "one argument"), "unexpected error for key remove: %v", err)
|
||||
|
||||
@@ -34,7 +34,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runKeyList(cmd.Context(), *globalOptions, args, globalOptions.term)
|
||||
return runKeyList(cmd.Context(), *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@@ -45,7 +45,7 @@ func runKeyList(ctx context.Context, gopts GlobalOptions, args []string, term ui
|
||||
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 := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -95,7 +95,7 @@ func listKeys(ctx context.Context, s *repository.Repository, gopts GlobalOptions
|
||||
}
|
||||
|
||||
if gopts.JSON {
|
||||
return json.NewEncoder(gopts.term.OutputWriter()).Encode(keys)
|
||||
return json.NewEncoder(gopts.Term.OutputWriter()).Encode(keys)
|
||||
}
|
||||
|
||||
tab := table.New()
|
||||
@@ -108,5 +108,5 @@ func listKeys(ctx context.Context, s *repository.Repository, gopts GlobalOptions
|
||||
tab.AddRow(key)
|
||||
}
|
||||
|
||||
return tab.Write(gopts.term.OutputWriter())
|
||||
return tab.Write(gopts.Term.OutputWriter())
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runKeyPasswd(cmd.Context(), *globalOptions, opts, args, globalOptions.term)
|
||||
return runKeyPasswd(cmd.Context(), *globalOptions, opts, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOption
|
||||
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 := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -31,7 +31,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runKeyRemove(cmd.Context(), *globalOptions, args, globalOptions.term)
|
||||
return runKeyRemove(cmd.Context(), *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@@ -42,7 +42,7 @@ func runKeyRemove(ctx context.Context, gopts GlobalOptions, args []string, term
|
||||
return fmt.Errorf("key remove expects one argument as the key id")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -34,7 +34,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
GroupID: cmdGroupDefault,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runList(cmd.Context(), *globalOptions, args, globalOptions.term)
|
||||
return runList(cmd.Context(), *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
ValidArgs: listAllowedArgs,
|
||||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||
@@ -43,7 +43,7 @@ Exit status is 12 if the password is incorrect.
|
||||
}
|
||||
|
||||
func runList(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
if len(args) != 1 {
|
||||
return errors.Fatal("type not specified")
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func testRunList(t testing.TB, gopts GlobalOptions, tpe string) restic.IDs {
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runList(ctx, gopts, []string{tpe}, gopts.term)
|
||||
return runList(ctx, gopts, []string{tpe}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
return parseIDsFromReader(t, buf)
|
||||
@@ -60,7 +60,7 @@ func testListSnapshots(t testing.TB, gopts GlobalOptions, expected int) restic.I
|
||||
// extract blob set from repository index
|
||||
func testListBlobs(t testing.TB, gopts GlobalOptions) (blobSetFromIndex restic.IDSet) {
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
_, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
|
||||
@@ -62,7 +62,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runLs(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runLs(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
opts.AddFlags(cmd.Flags())
|
||||
@@ -304,7 +304,7 @@ type toSortOutput struct {
|
||||
}
|
||||
|
||||
func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
termPrinter := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
termPrinter := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
if len(args) == 0 {
|
||||
return errors.Fatal("no snapshot ID specified, specify snapshot ID or use special ID 'latest'")
|
||||
@@ -383,11 +383,11 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri
|
||||
|
||||
if gopts.JSON {
|
||||
printer = &jsonLsPrinter{
|
||||
enc: json.NewEncoder(gopts.term.OutputWriter()),
|
||||
enc: json.NewEncoder(gopts.Term.OutputWriter()),
|
||||
}
|
||||
} else if opts.Ncdu {
|
||||
printer = &ncduLsPrinter{
|
||||
out: gopts.term.OutputWriter(),
|
||||
out: gopts.Term.OutputWriter(),
|
||||
}
|
||||
} else {
|
||||
printer = &textLsPrinter{
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func testRunLsWithOpts(t testing.TB, gopts GlobalOptions, opts LsOptions, args []string) []byte {
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.Quiet = true
|
||||
return runLs(context.TODO(), opts, gopts, args, gopts.term)
|
||||
return runLs(context.TODO(), opts, gopts, args, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
return buf.Bytes()
|
||||
|
||||
@@ -35,7 +35,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
GroupID: cmdGroupDefault,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runMigrate(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runMigrate(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptio
|
||||
}
|
||||
|
||||
func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
|
||||
@@ -83,7 +83,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runMount(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runMount(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (opts *MountOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
if opts.TimeTemplate == "" {
|
||||
return errors.Fatal("time template string cannot be empty")
|
||||
|
||||
@@ -64,7 +64,7 @@ func testRunMount(t testing.TB, gopts GlobalOptions, dir string, wg *sync.WaitGr
|
||||
TimeTemplate: time.RFC3339,
|
||||
}
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runMount(context.TODO(), opts, gopts, []string{dir}, gopts.term)
|
||||
return runMount(context.TODO(), opts, gopts, []string{dir}, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func checkSnapshots(t testing.TB, gopts GlobalOptions, mountpoint string, snapsh
|
||||
}
|
||||
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
_, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -177,7 +177,7 @@ func TestMount(t *testing.T) {
|
||||
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
// must list snapshots more than once
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
defer cleanup()
|
||||
|
||||
testRunInit(t, env.gopts)
|
||||
@@ -224,7 +224,7 @@ func TestMountSameTimestamps(t *testing.T) {
|
||||
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
// must list snapshots more than once
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
defer cleanup()
|
||||
|
||||
rtest.SetupTarTestFixture(t, env.base, filepath.Join("testdata", "repo-same-timestamps.tar.gz"))
|
||||
|
||||
@@ -24,7 +24,7 @@ Exit status is 1 if there was any error.
|
||||
GroupID: cmdGroupAdvanced,
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
globalOptions.term.Print("All Extended Options:")
|
||||
globalOptions.Term.Print("All Extended Options:")
|
||||
var maxLen int
|
||||
for _, opt := range options.List() {
|
||||
if l := len(opt.Namespace + "." + opt.Name); l > maxLen {
|
||||
@@ -32,7 +32,7 @@ Exit status is 1 if there was any error.
|
||||
}
|
||||
}
|
||||
for _, opt := range options.List() {
|
||||
globalOptions.term.Print(fmt.Sprintf(" %*s %s", -maxLen, opt.Namespace+"."+opt.Name, opt.Text))
|
||||
globalOptions.Term.Print(fmt.Sprintf(" %*s %s", -maxLen, opt.Namespace+"."+opt.Name, opt.Text))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runPrune(cmd.Context(), opts, *globalOptions, globalOptions.term)
|
||||
return runPrune(cmd.Context(), opts, *globalOptions, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term
|
||||
return errors.Fatal("--no-lock is only applicable in combination with --dry-run for prune command")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -23,13 +23,13 @@ func testRunPruneMustFail(t testing.TB, gopts GlobalOptions, opts PruneOptions)
|
||||
}
|
||||
|
||||
func testRunPruneOutput(t testing.TB, gopts GlobalOptions, opts PruneOptions) error {
|
||||
oldHook := gopts.backendTestHook
|
||||
gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
|
||||
oldHook := gopts.BackendTestHook
|
||||
gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
|
||||
defer func() {
|
||||
gopts.backendTestHook = oldHook
|
||||
gopts.BackendTestHook = oldHook
|
||||
}()
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), opts, gopts, gopts.term)
|
||||
return runPrune(context.TODO(), opts, gopts, gopts.Term)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func testRunForgetJSON(t testing.TB, gopts GlobalOptions, args ...string) {
|
||||
pruneOpts := PruneOptions{
|
||||
MaxUnused: "5%",
|
||||
}
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.term, args)
|
||||
return runForget(context.TODO(), opts, pruneOpts, gopts, gopts.Term, args)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -120,7 +120,7 @@ func testPrune(t *testing.T, pruneOpts PruneOptions, checkOpts CheckOptions) {
|
||||
createPrunableRepo(t, env)
|
||||
testRunPrune(t, env.gopts, pruneOpts)
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.term)
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.Term)
|
||||
return err
|
||||
}))
|
||||
}
|
||||
@@ -149,14 +149,14 @@ func TestPruneWithDamagedRepository(t *testing.T) {
|
||||
testListSnapshots(t, env.gopts, 1)
|
||||
removePacksExcept(env.gopts, t, oldPacks, false)
|
||||
|
||||
oldHook := env.gopts.backendTestHook
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
|
||||
oldHook := env.gopts.BackendTestHook
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) { return newListOnceBackend(r), nil }
|
||||
defer func() {
|
||||
env.gopts.backendTestHook = oldHook
|
||||
env.gopts.BackendTestHook = oldHook
|
||||
}()
|
||||
// prune should fail
|
||||
rtest.Equals(t, repository.ErrPacksMissing, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), pruneDefaultOptions, gopts, gopts.term)
|
||||
return runPrune(context.TODO(), pruneDefaultOptions, gopts, gopts.Term)
|
||||
}), "prune should have reported index not complete error")
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o
|
||||
testRunCheck(t, env.gopts)
|
||||
} else {
|
||||
rtest.Assert(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), optionsCheck, gopts, nil, gopts.term)
|
||||
_, err := runCheck(context.TODO(), optionsCheck, gopts, nil, gopts.Term)
|
||||
return err
|
||||
}) != nil,
|
||||
"check should have reported an error")
|
||||
@@ -240,7 +240,7 @@ func testEdgeCaseRepo(t *testing.T, tarfile string, optionsCheck CheckOptions, o
|
||||
testRunCheck(t, env.gopts)
|
||||
} else {
|
||||
rtest.Assert(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runPrune(context.TODO(), optionsPrune, gopts, gopts.term)
|
||||
return runPrune(context.TODO(), optionsPrune, gopts, gopts.Term)
|
||||
}) != nil,
|
||||
"prune should have reported an error")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ Exit status is 12 if the password is incorrect.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runRecover(cmd.Context(), *globalOptions, globalOptions.term)
|
||||
return runRecover(cmd.Context(), *globalOptions, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@@ -48,7 +48,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term ui.Terminal) erro
|
||||
return err
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
|
||||
func testRunRecover(t testing.TB, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRecover(context.TODO(), gopts, gopts.term)
|
||||
return runRecover(context.TODO(), gopts, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
func TestRecover(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
// must list index more than once
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
defer cleanup()
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
@@ -33,6 +33,6 @@ func TestRecover(t *testing.T) {
|
||||
testRunCheck(t, env.gopts)
|
||||
// check that the root tree is included in the snapshot
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runCat(context.TODO(), gopts, []string{"tree", ids[0].String() + ":" + sn.Tree.Str()}, gopts.term)
|
||||
return runCat(context.TODO(), gopts, []string{"tree", ids[0].String() + ":" + sn.Tree.Str()}, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runRebuildIndex(cmd.Context(), opts, *globalOptions, globalOptions.term)
|
||||
return runRebuildIndex(cmd.Context(), opts, *globalOptions, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func newRebuildIndexCommand(globalOptions *GlobalOptions) *cobra.Command {
|
||||
// must create a new instance of the run function as it captures opts
|
||||
// by reference
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runRebuildIndex(cmd.Context(), opts, *globalOptions, globalOptions.term)
|
||||
return runRebuildIndex(cmd.Context(), opts, *globalOptions, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func newRebuildIndexCommand(globalOptions *GlobalOptions) *cobra.Command {
|
||||
}
|
||||
|
||||
func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.Quiet = true
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
||||
func testRebuildIndex(t *testing.T, backendTestHook BackendWrapper) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -42,10 +42,10 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
||||
t.Fatalf("did not find hint for repair index command")
|
||||
}
|
||||
|
||||
env.gopts.backendTestHook = backendTestHook
|
||||
env.gopts.BackendTestHook = backendTestHook
|
||||
testRunRebuildIndex(t, env.gopts)
|
||||
|
||||
env.gopts.backendTestHook = nil
|
||||
env.gopts.BackendTestHook = nil
|
||||
out, err = testRunCheckOutput(t, env.gopts, false)
|
||||
if len(out) != 0 {
|
||||
t.Fatalf("expected no output from the checker, got: %v", out)
|
||||
@@ -125,12 +125,12 @@ func TestRebuildIndexFailsOnAppendOnly(t *testing.T) {
|
||||
datafile := filepath.Join("..", "..", "internal", "checker", "testdata", "duplicate-packs-in-index-test-repo.tar.gz")
|
||||
rtest.SetupTarTestFixture(t, env.base, datafile)
|
||||
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return &appendOnlyBackend{r}, nil
|
||||
}
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
gopts.Quiet = true
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.Term)
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
|
||||
@@ -32,7 +32,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runRepairPacks(cmd.Context(), *globalOptions, globalOptions.term, args)
|
||||
return runRepairPacks(cmd.Context(), *globalOptions, globalOptions.Term, args)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@@ -51,7 +51,7 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term ui.Terminal,
|
||||
return errors.Fatal("no ids specified")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
if err != nil {
|
||||
|
||||
@@ -52,7 +52,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runRepairSnapshots(cmd.Context(), *globalOptions, opts, args, globalOptions.term)
|
||||
return runRepairSnapshots(cmd.Context(), *globalOptions, opts, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (opts *RepairOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun, printer)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ func testRunRepairSnapshot(t testing.TB, gopts GlobalOptions, forget bool) {
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRepairSnapshots(context.TODO(), gopts, opts, nil, gopts.term)
|
||||
return runRepairSnapshots(context.TODO(), gopts, opts, nil, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runRestore(cmd.Context(), opts, *globalOptions, globalOptions.term, args)
|
||||
return runRestore(cmd.Context(), opts, *globalOptions, globalOptions.Term, args)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
|
||||
|
||||
var printer restoreui.ProgressPrinter
|
||||
if gopts.JSON {
|
||||
printer = restoreui.NewJSONProgress(term, gopts.verbosity)
|
||||
printer = restoreui.NewJSONProgress(term, gopts.Verbosity)
|
||||
} else {
|
||||
printer = restoreui.NewTextProgress(term, gopts.verbosity)
|
||||
printer = restoreui.NewTextProgress(term, gopts.Verbosity)
|
||||
}
|
||||
|
||||
excludePatternFns, err := opts.ExcludePatternOptions.CollectPatterns(printer.E)
|
||||
|
||||
@@ -31,7 +31,7 @@ func testRunRestoreExcludes(t testing.TB, gopts GlobalOptions, dir string, snaps
|
||||
|
||||
func testRunRestoreAssumeFailure(t testing.TB, snapshotID string, opts RestoreOptions, gopts GlobalOptions) error {
|
||||
return withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRestore(ctx, opts, gopts, gopts.term, []string{snapshotID})
|
||||
return runRestore(ctx, opts, gopts, gopts.Term, []string{snapshotID})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runRewrite(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runRewrite(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a
|
||||
return errors.Fatal("Nothing to do: no excludes provided and no new metadata provided")
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
|
||||
var (
|
||||
repo *repository.Repository
|
||||
|
||||
@@ -22,7 +22,7 @@ func testRunRewriteExclude(t testing.TB, gopts GlobalOptions, excludes []string,
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), opts, gopts, nil, gopts.term)
|
||||
return runRewrite(context.TODO(), opts, gopts, nil, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -43,7 +43,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 GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -119,7 +119,7 @@ func testRewriteMetadata(t *testing.T, metadata snapshotMetadataArgs) {
|
||||
|
||||
var snapshots []*data.Snapshot
|
||||
err := withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -159,7 +159,7 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
||||
createBasicRewriteRepo(t, env)
|
||||
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.term)
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.Term)
|
||||
}))
|
||||
// no new snapshot should be created as the snapshot already has a summary
|
||||
snapshots := testListSnapshots(t, env.gopts, 1)
|
||||
@@ -167,7 +167,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 GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
_, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -184,7 +184,7 @@ func TestRewriteSnaphotSummary(t *testing.T) {
|
||||
|
||||
// rewrite snapshot and lookup ID of new snapshot
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.term)
|
||||
return runRewrite(context.TODO(), RewriteOptions{SnapshotSummary: true}, gopts, []string{}, gopts.Term)
|
||||
}))
|
||||
newSnapshots := testListSnapshots(t, env.gopts, 2)
|
||||
newSnapshot := restic.NewIDSet(newSnapshots...).Sub(restic.NewIDSet(snapshots...)).List()[0]
|
||||
|
||||
@@ -43,7 +43,7 @@ Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runSelfUpdate(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runSelfUpdate(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func runSelfUpdate(ctx context.Context, opts SelfUpdateOptions, gopts GlobalOpti
|
||||
}
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(false, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(false, gopts.Verbosity, term)
|
||||
printer.P("writing restic to %v", opts.Output)
|
||||
|
||||
v, err := selfupdate.DownloadLatestStableRelease(ctx, opts.Output, version, printer.P)
|
||||
|
||||
@@ -38,7 +38,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runSnapshots(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runSnapshots(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (opts *SnapshotOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -105,7 +105,7 @@ func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions
|
||||
}
|
||||
|
||||
if gopts.JSON {
|
||||
err := printSnapshotGroupJSON(gopts.term.OutputWriter(), snapshotGroups, grouped)
|
||||
err := printSnapshotGroupJSON(gopts.Term.OutputWriter(), snapshotGroups, grouped)
|
||||
if err != nil {
|
||||
printer.E("error printing snapshots: %v", err)
|
||||
}
|
||||
@@ -118,12 +118,12 @@ func runSnapshots(ctx context.Context, opts SnapshotOptions, gopts GlobalOptions
|
||||
}
|
||||
|
||||
if grouped {
|
||||
err := PrintSnapshotGroupHeader(gopts.term.OutputWriter(), k)
|
||||
err := PrintSnapshotGroupHeader(gopts.Term.OutputWriter(), k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := PrintSnapshots(gopts.term.OutputWriter(), list, nil, opts.Compact)
|
||||
err := PrintSnapshots(gopts.Term.OutputWriter(), list, nil, opts.Compact)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snap
|
||||
gopts.JSON = true
|
||||
|
||||
opts := SnapshotOptions{}
|
||||
return runSnapshots(ctx, opts, gopts, []string{}, gopts.term)
|
||||
return runSnapshots(ctx, opts, gopts, []string{}, gopts.Term)
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runStats(cmd.Context(), opts, *globalOptions, args, globalOptions.term)
|
||||
return runStats(cmd.Context(), opts, *globalOptions, args, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args
|
||||
return err
|
||||
}
|
||||
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock, printer)
|
||||
if err != nil {
|
||||
@@ -170,7 +170,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args
|
||||
}
|
||||
|
||||
if gopts.JSON {
|
||||
err = json.NewEncoder(gopts.term.OutputWriter()).Encode(stats)
|
||||
err = json.NewEncoder(gopts.Term.OutputWriter()).Encode(stats)
|
||||
if err != nil {
|
||||
return fmt.Errorf("encoding output: %v", err)
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ Exit status is 12 if the password is incorrect.
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
finalizeSnapshotFilter(&opts.SnapshotFilter)
|
||||
return runTag(cmd.Context(), opts, *globalOptions, globalOptions.term, args)
|
||||
return runTag(cmd.Context(), opts, *globalOptions, globalOptions.Term, args)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -120,7 +119,7 @@ func changeTags(ctx context.Context, repo *repository.Repository, sn *data.Snaps
|
||||
}
|
||||
|
||||
func runTag(ctx context.Context, opts TagOptions, gopts GlobalOptions, term ui.Terminal, args []string) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
|
||||
if len(opts.SetTags) == 0 && len(opts.AddTags) == 0 && len(opts.RemoveTags) == 0 {
|
||||
return errors.Fatal("nothing to do!")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func testRunTag(t testing.TB, opts TagOptions, gopts GlobalOptions) {
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runTag(context.TODO(), opts, gopts, gopts.term, []string{})
|
||||
return runTag(context.TODO(), opts, gopts, gopts.Term, []string{})
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ Exit status is 1 if there was any error.
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runUnlock(cmd.Context(), opts, *globalOptions, globalOptions.term)
|
||||
return runUnlock(cmd.Context(), opts, *globalOptions, globalOptions.Term)
|
||||
},
|
||||
}
|
||||
opts.AddFlags(cmd.Flags())
|
||||
@@ -44,7 +44,7 @@ func (opts *UnlockOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func runUnlock(ctx context.Context, opts UnlockOptions, gopts GlobalOptions, term ui.Terminal) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, term)
|
||||
repo, err := OpenRepository(ctx, gopts, printer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -24,7 +24,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 := ui.NewProgressPrinter(globalOptions.JSON, globalOptions.Verbosity, globalOptions.Term)
|
||||
|
||||
if globalOptions.JSON {
|
||||
type jsonVersion struct {
|
||||
@@ -43,7 +43,7 @@ Exit status is 1 if there was any error.
|
||||
GoArch: runtime.GOARCH,
|
||||
}
|
||||
|
||||
err := json.NewEncoder(globalOptions.term.OutputWriter()).Encode(jsonS)
|
||||
err := json.NewEncoder(globalOptions.Term.OutputWriter()).Encode(jsonS)
|
||||
if err != nil {
|
||||
printer.E("JSON encode failed: %v\n", err)
|
||||
return
|
||||
|
||||
@@ -38,7 +38,7 @@ var version = "0.18.1-dev (compiled manually)"
|
||||
// TimeFormat is the format used for all timestamps printed by restic.
|
||||
const TimeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
type backendWrapper func(r backend.Backend) (backend.Backend, error)
|
||||
type BackendWrapper func(r backend.Backend) (backend.Backend, error)
|
||||
|
||||
// GlobalOptions hold all global options for restic.
|
||||
type GlobalOptions struct {
|
||||
@@ -63,22 +63,22 @@ type GlobalOptions struct {
|
||||
backend.TransportOptions
|
||||
limiter.Limits
|
||||
|
||||
password string
|
||||
term ui.Terminal
|
||||
Password string
|
||||
Term ui.Terminal
|
||||
|
||||
backends *location.Registry
|
||||
backendTestHook, backendInnerTestHook backendWrapper
|
||||
Backends *location.Registry
|
||||
BackendTestHook, BackendInnerTestHook BackendWrapper
|
||||
|
||||
// verbosity is set as follows:
|
||||
// Verbosity is set as follows:
|
||||
// 0 means: don't print any messages except errors, this is used when --quiet is specified
|
||||
// 1 is the default: print essential messages
|
||||
// 2 means: print more messages, report minor things, this is used when --verbose is specified
|
||||
// 3 means: print very detailed debug messages, this is used when --verbose=2 is specified
|
||||
verbosity uint
|
||||
Verbosity uint
|
||||
|
||||
Options []string
|
||||
|
||||
extended options.Options
|
||||
Extended options.Options
|
||||
}
|
||||
|
||||
func (opts *GlobalOptions) AddFlags(f *pflag.FlagSet) {
|
||||
@@ -134,18 +134,18 @@ func (opts *GlobalOptions) AddFlags(f *pflag.FlagSet) {
|
||||
|
||||
func (opts *GlobalOptions) PreRun(needsPassword bool) error {
|
||||
// set verbosity, default is one
|
||||
opts.verbosity = 1
|
||||
opts.Verbosity = 1
|
||||
if opts.Quiet && opts.Verbose > 0 {
|
||||
return errors.Fatal("--quiet and --verbose cannot be specified at the same time")
|
||||
}
|
||||
|
||||
switch {
|
||||
case opts.Verbose >= 2:
|
||||
opts.verbosity = 3
|
||||
opts.Verbosity = 3
|
||||
case opts.Verbose > 0:
|
||||
opts.verbosity = 2
|
||||
opts.Verbosity = 2
|
||||
case opts.Quiet:
|
||||
opts.verbosity = 0
|
||||
opts.Verbosity = 0
|
||||
}
|
||||
|
||||
// parse extended options
|
||||
@@ -153,7 +153,7 @@ func (opts *GlobalOptions) PreRun(needsPassword bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.extended = extendedOpts
|
||||
opts.Extended = extendedOpts
|
||||
if !needsPassword {
|
||||
return nil
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (opts *GlobalOptions) PreRun(needsPassword bool) error {
|
||||
if err != nil {
|
||||
return errors.Fatalf("Resolving password failed: %v", err)
|
||||
}
|
||||
opts.password = pwd
|
||||
opts.Password = pwd
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -209,17 +209,17 @@ func loadPasswordFromFile(pwdFile string) (string, error) {
|
||||
// the function leaks the password reading goroutine.
|
||||
func ReadPassword(ctx context.Context, gopts GlobalOptions, prompt string) (string, error) {
|
||||
if gopts.InsecureNoPassword {
|
||||
if gopts.password != "" {
|
||||
if gopts.Password != "" {
|
||||
return "", errors.Fatal("--insecure-no-password must not be specified together with providing a password via a cli option or environment variable")
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if gopts.password != "" {
|
||||
return gopts.password, nil
|
||||
if gopts.Password != "" {
|
||||
return gopts.Password, nil
|
||||
}
|
||||
|
||||
password, err := gopts.term.ReadPassword(ctx, prompt)
|
||||
password, err := gopts.Term.ReadPassword(ctx, prompt)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to read password: %w", err)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func ReadPasswordTwice(ctx context.Context, gopts GlobalOptions, prompt1, prompt
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if gopts.term.InputIsTerminal() {
|
||||
if gopts.Term.InputIsTerminal() {
|
||||
pw2, err := ReadPassword(ctx, gopts, prompt2)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -287,7 +287,7 @@ func OpenRepository(ctx context.Context, gopts GlobalOptions, printer progress.P
|
||||
return nil, err
|
||||
}
|
||||
|
||||
be, err := open(ctx, repo, gopts, gopts.extended, printer)
|
||||
be, err := open(ctx, repo, gopts, gopts.Extended, printer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -302,26 +302,26 @@ func OpenRepository(ctx context.Context, gopts GlobalOptions, printer progress.P
|
||||
}
|
||||
|
||||
passwordTriesLeft := 1
|
||||
if gopts.term.InputIsTerminal() && gopts.password == "" && !gopts.InsecureNoPassword {
|
||||
if gopts.Term.InputIsTerminal() && gopts.Password == "" && !gopts.InsecureNoPassword {
|
||||
passwordTriesLeft = 3
|
||||
}
|
||||
|
||||
for ; passwordTriesLeft > 0; passwordTriesLeft-- {
|
||||
gopts.password, err = ReadPassword(ctx, gopts, "enter password for repository: ")
|
||||
gopts.Password, err = ReadPassword(ctx, gopts, "enter password for repository: ")
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
if err != nil && passwordTriesLeft > 1 {
|
||||
gopts.password = ""
|
||||
gopts.Password = ""
|
||||
printer.E("%s. Try again", err)
|
||||
}
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
err = s.SearchKey(ctx, gopts.password, maxKeys, gopts.KeyHint)
|
||||
err = s.SearchKey(ctx, gopts.Password, maxKeys, gopts.KeyHint)
|
||||
if err != nil && passwordTriesLeft > 1 {
|
||||
gopts.password = ""
|
||||
gopts.Password = ""
|
||||
printer.E("%s. Try again", err)
|
||||
}
|
||||
}
|
||||
@@ -404,8 +404,8 @@ func parseConfig(loc location.Location, opts options.Options) (interface{}, erro
|
||||
}
|
||||
|
||||
func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.Options, create bool, printer progress.Printer) (backend.Backend, error) {
|
||||
debug.Log("parsing location %v", location.StripPassword(gopts.backends, s))
|
||||
loc, err := location.Parse(gopts.backends, s)
|
||||
debug.Log("parsing location %v", location.StripPassword(gopts.Backends, s))
|
||||
loc, err := location.Parse(gopts.Backends, s)
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("parsing repository location failed: %v", err)
|
||||
}
|
||||
@@ -424,7 +424,7 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.
|
||||
lim := limiter.NewStaticLimiter(gopts.Limits)
|
||||
rt = lim.Transport(rt)
|
||||
|
||||
factory := gopts.backends.Lookup(loc.Scheme)
|
||||
factory := gopts.Backends.Lookup(loc.Scheme)
|
||||
if factory == nil {
|
||||
return nil, errors.Fatalf("invalid backend: %q", loc.Scheme)
|
||||
}
|
||||
@@ -438,22 +438,22 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.
|
||||
|
||||
if errors.Is(err, backend.ErrNoRepository) {
|
||||
//nolint:staticcheck // capitalized error string is intentional
|
||||
return nil, fmt.Errorf("Fatal: %w at %v: %v", ErrNoRepository, location.StripPassword(gopts.backends, s), err)
|
||||
return nil, fmt.Errorf("Fatal: %w at %v: %v", ErrNoRepository, location.StripPassword(gopts.Backends, s), err)
|
||||
}
|
||||
if err != nil {
|
||||
if create {
|
||||
// init already wraps the error message
|
||||
return nil, err
|
||||
}
|
||||
return nil, errors.Fatalf("unable to open repository at %v: %v", location.StripPassword(gopts.backends, s), err)
|
||||
return nil, errors.Fatalf("unable to open repository at %v: %v", location.StripPassword(gopts.Backends, s), err)
|
||||
}
|
||||
|
||||
// wrap with debug logging and connection limiting
|
||||
be = logger.New(sema.NewBackend(be))
|
||||
|
||||
// wrap backend if a test specified an inner hook
|
||||
if gopts.backendInnerTestHook != nil {
|
||||
be, err = gopts.backendInnerTestHook(be)
|
||||
if gopts.BackendInnerTestHook != nil {
|
||||
be, err = gopts.BackendInnerTestHook(be)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -472,8 +472,8 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.
|
||||
be = retry.New(be, 15*time.Minute, report, success)
|
||||
|
||||
// wrap backend if a test specified a hook
|
||||
if gopts.backendTestHook != nil {
|
||||
be, err = gopts.backendTestHook(be)
|
||||
if gopts.BackendTestHook != nil {
|
||||
be, err = gopts.BackendTestHook(be)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -493,10 +493,10 @@ func open(ctx context.Context, s string, gopts GlobalOptions, opts options.Optio
|
||||
fi, err := be.Stat(ctx, backend.Handle{Type: restic.ConfigFile})
|
||||
if be.IsNotExist(err) {
|
||||
//nolint:staticcheck // capitalized error string is intentional
|
||||
return nil, fmt.Errorf("Fatal: %w: unable to open config file: %v\nIs there a repository at the following location?\n%v", ErrNoRepository, err, location.StripPassword(gopts.backends, s))
|
||||
return nil, fmt.Errorf("Fatal: %w: unable to open config file: %v\nIs there a repository at the following location?\n%v", ErrNoRepository, err, location.StripPassword(gopts.Backends, s))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("unable to open config file: %v\nIs there a repository at the following location?\n%v", err, location.StripPassword(gopts.backends, s))
|
||||
return nil, errors.Fatalf("unable to open config file: %v\nIs there a repository at the following location?\n%v", err, location.StripPassword(gopts.Backends, s))
|
||||
}
|
||||
|
||||
if fi.Size == 0 {
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestReadEmptyPassword(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, "", password, "got unexpected password")
|
||||
|
||||
opts.password = "invalid"
|
||||
opts.Password = "invalid"
|
||||
_, err = ReadPassword(context.TODO(), opts, "test")
|
||||
rtest.Assert(t, strings.Contains(err.Error(), "must not be specified together with providing a password via a cli option or environment variable"), "unexpected error message, got %v", err)
|
||||
}
|
||||
|
||||
@@ -213,13 +213,13 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
||||
Repo: env.repo,
|
||||
Quiet: true,
|
||||
CacheDir: env.cache,
|
||||
password: rtest.TestPassword,
|
||||
extended: make(options.Options),
|
||||
Password: rtest.TestPassword,
|
||||
Extended: make(options.Options),
|
||||
|
||||
// replace this hook with "nil" if listing a filetype more than once is necessary
|
||||
backendTestHook: func(r backend.Backend) (backend.Backend, error) { return newOrderedListOnceBackend(r), nil },
|
||||
BackendTestHook: func(r backend.Backend) (backend.Backend, error) { return newOrderedListOnceBackend(r), nil },
|
||||
// start with default set of backends
|
||||
backends: all.Backends(),
|
||||
Backends: all.Backends(),
|
||||
}
|
||||
|
||||
cleanup = func() {
|
||||
@@ -243,7 +243,7 @@ func testSetupBackupData(t testing.TB, env *testEnvironment) string {
|
||||
func listPacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
var packs restic.IDSet
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(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 GlobalOptions, t *testing.T) restic.IDSet {
|
||||
func listTreePacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
var treePacks restic.IDSet
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
ctx, r, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -281,7 +281,7 @@ func listTreePacks(gopts GlobalOptions, t *testing.T) restic.IDSet {
|
||||
|
||||
func captureBackend(gopts *GlobalOptions) func() backend.Backend {
|
||||
var be backend.Backend
|
||||
gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
be = r
|
||||
return r, nil
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func captureBackend(gopts *GlobalOptions) func() backend.Backend {
|
||||
func removePacks(gopts GlobalOptions, t testing.TB, remove restic.IDSet) {
|
||||
be := captureBackend(&gopts)
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(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 GlobalOptions, t testing.TB, remove restic.IDSet) {
|
||||
func removePacksExcept(gopts GlobalOptions, t testing.TB, keep restic.IDSet, removeTreePacks bool) {
|
||||
be := captureBackend(&gopts)
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(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 GlobalOptions, id restic.ID) *data.Snapshot {
|
||||
var snapshot *data.Snapshot
|
||||
err := withTermStatus(t, gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
_, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -432,7 +432,7 @@ func withTermStatusRaw(stdin io.ReadCloser, stdout, stderr io.Writer, gopts Glob
|
||||
var wg sync.WaitGroup
|
||||
|
||||
term := termstatus.New(stdin, stdout, stderr, gopts.Quiet)
|
||||
gopts.term = term
|
||||
gopts.Term = term
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestListOnce(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return newOrderedListOnceBackend(r), nil
|
||||
}
|
||||
pruneOpts := PruneOptions{MaxUnused: "0"}
|
||||
@@ -89,14 +89,14 @@ func TestListOnce(t *testing.T) {
|
||||
createPrunableRepo(t, env)
|
||||
testRunPrune(t, env.gopts, pruneOpts)
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.term)
|
||||
_, err := runCheck(context.TODO(), checkOpts, gopts, nil, gopts.Term)
|
||||
return err
|
||||
}))
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.term)
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts, gopts.Term)
|
||||
}))
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, gopts, gopts.term)
|
||||
return runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, gopts, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestBackendLoadWriteTo(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
// setup backend which only works if it's WriteTo method is correctly propagated upwards
|
||||
env.gopts.backendInnerTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendInnerTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return &onlyLoadWithWriteToBackend{Backend: r}, nil
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestFindListOnce(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
env.gopts.backendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
return newOrderedListOnceBackend(r), nil
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func TestFindListOnce(t *testing.T) {
|
||||
|
||||
var snapshotIDs restic.IDSet
|
||||
rtest.OK(t, withTermStatus(t, env.gopts, func(ctx context.Context, gopts GlobalOptions) error {
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.verbosity, gopts.term)
|
||||
printer := ui.NewProgressPrinter(gopts.JSON, gopts.Verbosity, gopts.Term)
|
||||
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, false, printer)
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
@@ -214,7 +214,7 @@ func TestBackendRetryConfig(t *testing.T) {
|
||||
|
||||
var wrappedBackend *failConfigOnceBackend
|
||||
// cause config loading to fail once
|
||||
env.gopts.backendInnerTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
env.gopts.BackendInnerTestHook = func(r backend.Backend) (backend.Backend, error) {
|
||||
wrappedBackend = &failConfigOnceBackend{Backend: r}
|
||||
return wrappedBackend, nil
|
||||
}
|
||||
|
||||
@@ -174,12 +174,12 @@ func main() {
|
||||
version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
globalOptions := GlobalOptions{
|
||||
backends: all.Backends(),
|
||||
Backends: all.Backends(),
|
||||
}
|
||||
func() {
|
||||
term, cancel := termstatus.Setup(os.Stdin, os.Stdout, os.Stderr, globalOptions.Quiet)
|
||||
defer cancel()
|
||||
globalOptions.term = term
|
||||
globalOptions.Term = term
|
||||
ctx := createGlobalContext(os.Stderr)
|
||||
err = newRootCommand(&globalOptions).ExecuteContext(ctx)
|
||||
switch err {
|
||||
|
||||
@@ -108,14 +108,14 @@ func fillSecondaryGlobalOpts(ctx context.Context, opts secondaryRepoOptions, gop
|
||||
}
|
||||
|
||||
if opts.password != "" {
|
||||
dstGopts.password = opts.password
|
||||
dstGopts.Password = opts.password
|
||||
} else {
|
||||
dstGopts.password, err = resolvePassword(&dstGopts, pwdEnv)
|
||||
dstGopts.Password, err = resolvePassword(&dstGopts, pwdEnv)
|
||||
if err != nil {
|
||||
return GlobalOptions{}, false, err
|
||||
}
|
||||
}
|
||||
dstGopts.password, err = ReadPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ")
|
||||
dstGopts.Password, err = ReadPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ")
|
||||
if err != nil {
|
||||
return GlobalOptions{}, false, err
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
Repo: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
},
|
||||
FromRepo: true,
|
||||
},
|
||||
@@ -40,7 +40,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
RepositoryFile: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
PasswordFile: "passwordFileDst",
|
||||
},
|
||||
FromRepo: true,
|
||||
@@ -53,7 +53,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
RepositoryFile: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
PasswordCommand: "echo secretDst",
|
||||
},
|
||||
FromRepo: true,
|
||||
@@ -66,7 +66,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
Repo: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -77,7 +77,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
RepositoryFile: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
PasswordFile: "passwordFileDst",
|
||||
},
|
||||
},
|
||||
@@ -89,7 +89,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
},
|
||||
DstGOpts: GlobalOptions{
|
||||
RepositoryFile: "backupDst",
|
||||
password: "secretDst",
|
||||
Password: "secretDst",
|
||||
PasswordCommand: "echo secretDst",
|
||||
},
|
||||
},
|
||||
@@ -150,7 +150,7 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
|
||||
var gOpts = GlobalOptions{
|
||||
Repo: "backupSrc",
|
||||
RepositoryFile: "backupSrc",
|
||||
password: "secretSrc",
|
||||
Password: "secretSrc",
|
||||
PasswordFile: "passwordFileSrc",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user