allow argumentless flags

This commit is contained in:
cupcakearmy 2021-10-25 18:29:59 +02:00
parent 2789502c89
commit 6137e31c3b
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
4 changed files with 18 additions and 3 deletions

View File

@ -18,6 +18,8 @@ backend:
In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command. In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command.
For more detail see the [location docs](/location/options) for options, as they are the same For more detail see the [location docs](/location/options) for options, as they are the same.
> For flags without arguments you can set them to `true`. They will be handled accordingly.
> :ToCPrevNext > :ToCPrevNext

View File

@ -18,4 +18,6 @@ locations:
In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command. In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command.
> For flags without arguments you can set them to `true`. They will be handled accordingly.
> :ToCPrevNext > :ToCPrevNext

View File

@ -239,7 +239,18 @@ func getOptions(options Options, key string) []string {
var selected []string var selected []string
for k, values := range options[key] { for k, values := range options[key] {
for _, value := range values { for _, value := range values {
selected = append(selected, fmt.Sprintf("--%s", k), value) // Bool
asBool, ok := value.(bool)
if ok && asBool {
selected = append(selected, fmt.Sprintf("--%s", k))
continue
}
// String
asString, ok := value.(string)
if ok {
selected = append(selected, fmt.Sprintf("--%s", k), asString)
continue
}
} }
} }
return selected return selected

View File

@ -30,7 +30,7 @@ type Hooks struct {
Failure HookArray `yaml:"failure,omitempty"` Failure HookArray `yaml:"failure,omitempty"`
} }
type Options map[string]map[string][]string type Options map[string]map[string][]interface{}
type Location struct { type Location struct {
name string `yaml:",omitempty"` name string `yaml:",omitempty"`