Add global config for passing '--option' flags
continuous-integration/drone/push Build is passing Details

This commit is contained in:
IamTheFij 2022-11-03 15:34:17 -07:00
parent 8b5d15d4b2
commit c0e1795a80
2 changed files with 19 additions and 10 deletions

View File

@ -187,16 +187,17 @@ func (fo ForgetOpts) ToArgs() (args []string) {
} }
type ResticGlobalOpts struct { type ResticGlobalOpts struct {
CaCertFile string `hcl:"CaCertFile,optional"` CaCertFile string `hcl:"CaCertFile,optional"`
CacheDir string `hcl:"CacheDir,optional"` CacheDir string `hcl:"CacheDir,optional"`
PasswordFile string `hcl:"PasswordFile,optional"` PasswordFile string `hcl:"PasswordFile,optional"`
TLSClientCertFile string `hcl:"TlsClientCertFile,optional"` TLSClientCertFile string `hcl:"TlsClientCertFile,optional"`
LimitDownload int `hcl:"LimitDownload,optional"` LimitDownload int `hcl:"LimitDownload,optional"`
LimitUpload int `hcl:"LimitUpload,optional"` LimitUpload int `hcl:"LimitUpload,optional"`
VerboseLevel int `hcl:"VerboseLevel,optional"` Options map[string]string `hcl:"Options,optional"`
CleanupCache bool `hcl:"CleanupCache,optional"` VerboseLevel int `hcl:"VerboseLevel,optional"`
NoCache bool `hcl:"NoCache,optional"` CleanupCache bool `hcl:"CleanupCache,optional"`
NoLock bool `hcl:"NoLock,optional"` NoCache bool `hcl:"NoCache,optional"`
NoLock bool `hcl:"NoLock,optional"`
} }
func (glo ResticGlobalOpts) ToArgs() (args []string) { 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-cache", glo.NoCache)
args = maybeAddArgBool(args, "--no-lock", glo.NoLock) 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 return args
} }

View File

@ -34,6 +34,9 @@ func TestGlobalOptions(t *testing.T) {
CleanupCache: true, CleanupCache: true,
NoCache: true, NoCache: true,
NoLock: true, NoLock: true,
Options: map[string]string{
"key": "a long value",
},
}.ToArgs() }.ToArgs()
expected := []string{ expected := []string{
@ -47,6 +50,7 @@ func TestGlobalOptions(t *testing.T) {
"--cleanup-cache", "--cleanup-cache",
"--no-cache", "--no-cache",
"--no-lock", "--no-lock",
"--option key='a long value'",
} }
AssertEqual(t, "args didn't match", expected, args) AssertEqual(t, "args didn't match", expected, args)