mirror of
https://github.com/restic/restic.git
synced 2026-06-27 02:54:19 +00:00
backup: move options finalization to BackupOptions.Finalize
This commit is contained in:
+20
-16
@@ -53,22 +53,7 @@ Exit status is 11 if the repository is already locked.
|
||||
Exit status is 12 if the password is incorrect.
|
||||
`,
|
||||
PreRunE: func(_ *cobra.Command, _ []string) error {
|
||||
if envVal := os.Getenv("RESTIC_READ_CONCURRENCY"); envVal != "" && !opts.readConcurrencyFlag.Changed {
|
||||
n, err := strconv.ParseUint(envVal, 10, 32)
|
||||
if err != nil {
|
||||
return errors.Fatalf("invalid value for RESTIC_READ_CONCURRENCY %q: %v", envVal, err)
|
||||
}
|
||||
opts.ReadConcurrency = uint(n)
|
||||
}
|
||||
if opts.Host == "" {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
debug.Log("os.Hostname() returned err: %v", err)
|
||||
return nil
|
||||
}
|
||||
opts.Host = hostname
|
||||
}
|
||||
return nil
|
||||
return opts.Finalize()
|
||||
},
|
||||
GroupID: cmdGroupDefault,
|
||||
DisableAutoGenTag: true,
|
||||
@@ -163,6 +148,25 @@ func (opts *BackupOptions) AddFlags(f *pflag.FlagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
func (opts *BackupOptions) Finalize() error {
|
||||
if envVal := os.Getenv("RESTIC_READ_CONCURRENCY"); envVal != "" && !opts.readConcurrencyFlag.Changed {
|
||||
n, err := strconv.ParseUint(envVal, 10, 32)
|
||||
if err != nil {
|
||||
return errors.Fatalf("invalid value for RESTIC_READ_CONCURRENCY %q: %v", envVal, err)
|
||||
}
|
||||
opts.ReadConcurrency = uint(n)
|
||||
}
|
||||
if opts.Host == "" {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
debug.Log("os.Hostname() returned err: %v", err)
|
||||
return nil
|
||||
}
|
||||
opts.Host = hostname
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var backupFSTestHook func(fs fs.FS) fs.FS
|
||||
|
||||
// ErrInvalidSourceData is used to report an incomplete backup
|
||||
|
||||
Reference in New Issue
Block a user