From 7ae289125260e7af5d7810bf560f2546c7bc6b19 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 8 May 2021 13:15:30 +0100 Subject: [PATCH] fs: Add Exclusive parameter to Option to choose Examples only #3455 --- fs/backend_config.go | 8 +++++--- fs/config/ui.go | 2 +- fs/fs.go | 1 + fs/fs_test.go | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/backend_config.go b/fs/backend_config.go index 47fb02fbb..9516ac250 100644 --- a/fs/backend_config.go +++ b/fs/backend_config.go @@ -161,6 +161,7 @@ func ConfigConfirm(state string, Default bool, name string, help string) (*Confi Value: "false", Help: "No", }}, + Exclusive: true, }, }, nil } @@ -182,9 +183,10 @@ func ConfigChooseFixed(state string, name string, help string, items []OptionExa choose := &ConfigOut{ State: state, Option: &Option{ - Name: name, - Help: help, - Examples: items, + Name: name, + Help: help, + Examples: items, + Exclusive: true, }, } choose.Option.Default = choose.Option.Examples[0].Value diff --git a/fs/config/ui.go b/fs/config/ui.go index c68dc183c..dbd4a512c 100644 --- a/fs/config/ui.go +++ b/fs/config/ui.go @@ -402,7 +402,7 @@ func ChooseOption(o *fs.Option, name string) string { help = append(help, example.Help) } } - in = Choose(o.Name, values, help, true) + in = Choose(o.Name, values, help, !o.Exclusive) } else { fmt.Printf("%s> ", o.Name) in = ReadLine() diff --git a/fs/fs.go b/fs/fs.go index c0bd0e65e..0532b24ec 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -184,6 +184,7 @@ type Option struct { IsPassword bool // set if the option is a password NoPrefix bool // set if the option for this should not use the backend prefix Advanced bool // set if this is an advanced config option + Exclusive bool // set if the answer can only be one of the examples } // BaseOption is an alias for Option used internally diff --git a/fs/fs_test.go b/fs/fs_test.go index 1f7aba038..4dad61f01 100644 --- a/fs/fs_test.go +++ b/fs/fs_test.go @@ -242,6 +242,7 @@ func TestOptionMarshalJSON(t *testing.T) { "IsPassword": false, "NoPrefix": false, "Advanced": true, +"Exclusive": false, "DefaultStr": "false", "ValueStr": "true", "Type": "bool"