allow options for backend

pull/87/head
cupcakearmy 4 years ago
parent 41736ea3c4
commit 61673bd88b
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

@ -23,6 +23,7 @@ type Backend struct {
Key string `yaml:"key,omitempty"` Key string `yaml:"key,omitempty"`
Env map[string]string `yaml:"env,omitempty"` Env map[string]string `yaml:"env,omitempty"`
Rest BackendRest `yaml:"rest,omitempty"` Rest BackendRest `yaml:"rest,omitempty"`
Options Options `yaml:"options,omitempty"`
} }
func GetBackend(name string) (Backend, bool) { func GetBackend(name string) (Backend, bool) {

@ -12,7 +12,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.1.0" const VERSION = "1.1.1"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false
@ -220,3 +220,13 @@ func (c *Config) SaveConfig() error {
return viper.WriteConfig() return viper.WriteConfig()
} }
func getOptions(options Options, key string) []string {
var selected []string
for k, values := range options[key] {
for _, value := range values {
selected = append(selected, fmt.Sprintf("--%s", k), value)
}
}
return selected
}

@ -78,17 +78,6 @@ func (l Location) validate(c *Config) error {
return nil return nil
} }
func (l Location) getOptions(key string) []string {
var options []string
saved := l.Options[key]
for k, values := range saved {
for _, value := range values {
options = append(options, fmt.Sprintf("--%s", k), value)
}
}
return options
}
func ExecuteHooks(commands []string, options ExecuteOptions) error { func ExecuteHooks(commands []string, options ExecuteOptions) error {
if len(commands) == 0 { if len(commands) == 0 {
return nil return nil
@ -164,9 +153,11 @@ func (l Location) Backup(cron bool) []error {
continue continue
} }
flags := l.getOptions("backup") lFlags := getOptions(l.Options, "backup")
bFlags := getOptions(backend.Options, "backup")
cmd := []string{"backup"} cmd := []string{"backup"}
cmd = append(cmd, flags...) cmd = append(cmd, lFlags...)
cmd = append(cmd, bFlags...)
if cron { if cron {
cmd = append(cmd, "--tag", "cron") cmd = append(cmd, "--tag", "cron")
} }
@ -232,7 +223,8 @@ func (l Location) Forget(prune bool, dry bool) error {
options := ExecuteOptions{ options := ExecuteOptions{
Envs: env, Envs: env,
} }
flags := l.getOptions("forget") lFlags := getOptions(l.Options, "forget")
bFlags := getOptions(backend.Options, "forget")
cmd := []string{"forget", "--path", path} cmd := []string{"forget", "--path", path}
if prune { if prune {
cmd = append(cmd, "--prune") cmd = append(cmd, "--prune")
@ -240,7 +232,8 @@ func (l Location) Forget(prune bool, dry bool) error {
if dry { if dry {
cmd = append(cmd, "--dry-run") cmd = append(cmd, "--dry-run")
} }
cmd = append(cmd, flags...) cmd = append(cmd, lFlags...)
cmd = append(cmd, bFlags...)
out, err := ExecuteResticCommand(options, cmd...) out, err := ExecuteResticCommand(options, cmd...)
if VERBOSE { if VERBOSE {
colors.Faint.Println(out) colors.Faint.Println(out)

Loading…
Cancel
Save