Use options when calling check or init (#199)

This commit is contained in:
Chosto 2022-09-13 15:15:02 +02:00 committed by GitHub
parent 83eeb847ac
commit b830667264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -122,13 +122,17 @@ func (b Backend) validate() error {
}
options := ExecuteOptions{Envs: env, Silent: true}
// Check if already initialized
_, _, err = ExecuteResticCommand(options, "check")
cmd := []string{"check"}
cmd = append(cmd, combineBackendOptions("check", b)...)
_, _, err = ExecuteResticCommand(options, cmd...)
if err == nil {
return nil
} else {
// If not initialize
colors.Body.Printf("Initializing backend \"%s\"...\n", b.name)
_, _, err := ExecuteResticCommand(options, "init")
cmd := []string{"init"}
cmd = append(cmd, combineBackendOptions("init", b)...)
_, _, err := ExecuteResticCommand(options, cmd...)
return err
}
}

View File

@ -303,7 +303,17 @@ func getOptions(options Options, keys []string) []string {
return selected
}
func combineOptions(key string, l Location, b Backend) []string {
func combineBackendOptions(key string, b Backend) []string {
// Priority: backend > global
var options []string
gFlags := getOptions(GetConfig().Global, []string{key})
bFlags := getOptions(b.Options, []string{"all", key})
options = append(options, gFlags...)
options = append(options, bFlags...)
return options
}
func combineAllOptions(key string, l Location, b Backend) []string {
// Priority: location > backend > global
var options []string
gFlags := getOptions(GetConfig().Global, []string{key})

View File

@ -216,7 +216,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
}
cmd := []string{"backup"}
cmd = append(cmd, combineOptions("backup", l, backend)...)
cmd = append(cmd, combineAllOptions("backup", l, backend)...)
if cron {
cmd = append(cmd, "--tag", buildTag("cron"))
}
@ -342,7 +342,7 @@ func (l Location) Forget(prune bool, dry bool) error {
if dry {
cmd = append(cmd, "--dry-run")
}
cmd = append(cmd, combineOptions("forget", l, backend)...)
cmd = append(cmd, combineAllOptions("forget", l, backend)...)
_, _, err = ExecuteResticCommand(options, cmd...)
if err != nil {
return err