From b830667264f66ee5d333ec5f5b4ce3fe494e6d44 Mon Sep 17 00:00:00 2001 From: Chosto Date: Tue, 13 Sep 2022 15:15:02 +0200 Subject: [PATCH] Use options when calling check or init (#199) --- internal/backend.go | 8 ++++++-- internal/config.go | 12 +++++++++++- internal/location.go | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/backend.go b/internal/backend.go index fa3afcc..0a3c177 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -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 } } diff --git a/internal/config.go b/internal/config.go index 70f3dca..491bda4 100644 --- a/internal/config.go +++ b/internal/config.go @@ -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}) diff --git a/internal/location.go b/internal/location.go index 5dae649..d4c73e7 100644 --- a/internal/location.go +++ b/internal/location.go @@ -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