From 6137e31c3b48321940ea6578837703bda117fc98 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 25 Oct 2021 18:29:59 +0200 Subject: [PATCH] allow argumentless flags --- docs/markdown/backend/options.md | 4 +++- docs/markdown/location/options.md | 2 ++ internal/config.go | 13 ++++++++++++- internal/location.go | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/markdown/backend/options.md b/docs/markdown/backend/options.md index 10c4561..2a49a56 100644 --- a/docs/markdown/backend/options.md +++ b/docs/markdown/backend/options.md @@ -18,6 +18,8 @@ backend: 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 diff --git a/docs/markdown/location/options.md b/docs/markdown/location/options.md index e0bd0f9..7ac90c6 100644 --- a/docs/markdown/location/options.md +++ b/docs/markdown/location/options.md @@ -18,4 +18,6 @@ locations: 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 diff --git a/internal/config.go b/internal/config.go index 1c548cf..61502ad 100644 --- a/internal/config.go +++ b/internal/config.go @@ -239,7 +239,18 @@ 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) + // 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 diff --git a/internal/location.go b/internal/location.go index aaac32f..7c669a5 100644 --- a/internal/location.go +++ b/internal/location.go @@ -30,7 +30,7 @@ type Hooks struct { Failure HookArray `yaml:"failure,omitempty"` } -type Options map[string]map[string][]string +type Options map[string]map[string][]interface{} type Location struct { name string `yaml:",omitempty"`