From c0e1795a80a4fd7e0b16ef88ab6229936f3b4e97 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 3 Nov 2022 15:34:17 -0700 Subject: [PATCH] Add global config for passing '--option' flags --- restic.go | 25 +++++++++++++++---------- restic_test.go | 4 ++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/restic.go b/restic.go index d95599f..42cdd2f 100644 --- a/restic.go +++ b/restic.go @@ -187,16 +187,17 @@ func (fo ForgetOpts) ToArgs() (args []string) { } type ResticGlobalOpts struct { - CaCertFile string `hcl:"CaCertFile,optional"` - CacheDir string `hcl:"CacheDir,optional"` - PasswordFile string `hcl:"PasswordFile,optional"` - TLSClientCertFile string `hcl:"TlsClientCertFile,optional"` - LimitDownload int `hcl:"LimitDownload,optional"` - LimitUpload int `hcl:"LimitUpload,optional"` - VerboseLevel int `hcl:"VerboseLevel,optional"` - CleanupCache bool `hcl:"CleanupCache,optional"` - NoCache bool `hcl:"NoCache,optional"` - NoLock bool `hcl:"NoLock,optional"` + CaCertFile string `hcl:"CaCertFile,optional"` + CacheDir string `hcl:"CacheDir,optional"` + PasswordFile string `hcl:"PasswordFile,optional"` + TLSClientCertFile string `hcl:"TlsClientCertFile,optional"` + LimitDownload int `hcl:"LimitDownload,optional"` + LimitUpload int `hcl:"LimitUpload,optional"` + Options map[string]string `hcl:"Options,optional"` + VerboseLevel int `hcl:"VerboseLevel,optional"` + CleanupCache bool `hcl:"CleanupCache,optional"` + NoCache bool `hcl:"NoCache,optional"` + NoLock bool `hcl:"NoLock,optional"` } func (glo ResticGlobalOpts) ToArgs() (args []string) { @@ -211,6 +212,10 @@ func (glo ResticGlobalOpts) ToArgs() (args []string) { args = maybeAddArgBool(args, "--no-cache", glo.NoCache) args = maybeAddArgBool(args, "--no-lock", glo.NoLock) + for key, value := range glo.Options { + args = append(args, fmt.Sprintf("--option %s='%s'", key, value)) + } + return args } diff --git a/restic_test.go b/restic_test.go index 350dc00..c173ffe 100644 --- a/restic_test.go +++ b/restic_test.go @@ -34,6 +34,9 @@ func TestGlobalOptions(t *testing.T) { CleanupCache: true, NoCache: true, NoLock: true, + Options: map[string]string{ + "key": "a long value", + }, }.ToArgs() expected := []string{ @@ -47,6 +50,7 @@ func TestGlobalOptions(t *testing.T) { "--cleanup-cache", "--no-cache", "--no-lock", + "--option key='a long value'", } AssertEqual(t, "args didn't match", expected, args)