From 276c4241062a668418dda916479d3014d3cd967d Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 17 Apr 2021 13:04:40 +0200 Subject: [PATCH] pass env of backends to restic --- internal/backend.go | 8 +++++++- internal/config.go | 2 +- internal/utils.go | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/backend.go b/internal/backend.go index a0bdbd5..8fb1b7c 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -41,6 +41,9 @@ func (b Backend) getEnv() (map[string]string, error) { env["RESTIC_PASSWORD"] = b.Key repo, err := b.generateRepo() env["RESTIC_REPOSITORY"] = repo + for key, value := range b.Env { + env[strings.ToUpper(key)] = value + } return env, err } @@ -88,8 +91,11 @@ func (b Backend) validate() error { return nil } else { // If not initialize + colors.Body.Printf("Initializing backend \"%s\"...\n", b.name) out, err := ExecuteResticCommand(options, "init") - colors.Faint.Println(out) + if VERBOSE { + colors.Faint.Println(out) + } return err } } diff --git a/internal/config.go b/internal/config.go index 77611e4..996a1d6 100644 --- a/internal/config.go +++ b/internal/config.go @@ -113,7 +113,7 @@ func (c *Config) Describe() { if len(b.Env) > 0 { tmp := "" for option, value := range b.Env { - tmp += fmt.Sprintf("\n\t%s %s %s", colors.Success.Sprint("✧"), option, colors.Faint.Sprint(value)) + tmp += fmt.Sprintf("\n\t%s %s %s", colors.Success.Sprint("✧"), strings.ToUpper(option), colors.Faint.Sprint(value)) } colors.PrintDescription("Env", tmp) } diff --git a/internal/utils.go b/internal/utils.go index febc060..cd32e9b 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -6,6 +6,8 @@ import ( "io" "os" "os/exec" + + "github.com/cupcakearmy/autorestic/internal/colors" ) func CheckIfCommandIsCallable(cmd string) bool { @@ -32,6 +34,10 @@ func ExecuteCommand(options ExecuteOptions, args ...string) (string, error) { cmd.Env = env cmd.Dir = options.Dir + if VERBOSE { + colors.Faint.Printf("> Executing: %s\n", cmd) + } + var out bytes.Buffer var error bytes.Buffer cmd.Stdout = &out