fs: Add Exclusive parameter to Option to choose Examples only #3455

This commit is contained in:
Nick Craig-Wood 2021-05-08 13:15:30 +01:00
parent 99caf79ffe
commit 7ae2891252
4 changed files with 8 additions and 4 deletions

View File

@ -161,6 +161,7 @@ func ConfigConfirm(state string, Default bool, name string, help string) (*Confi
Value: "false", Value: "false",
Help: "No", Help: "No",
}}, }},
Exclusive: true,
}, },
}, nil }, nil
} }
@ -182,9 +183,10 @@ func ConfigChooseFixed(state string, name string, help string, items []OptionExa
choose := &ConfigOut{ choose := &ConfigOut{
State: state, State: state,
Option: &Option{ Option: &Option{
Name: name, Name: name,
Help: help, Help: help,
Examples: items, Examples: items,
Exclusive: true,
}, },
} }
choose.Option.Default = choose.Option.Examples[0].Value choose.Option.Default = choose.Option.Examples[0].Value

View File

@ -402,7 +402,7 @@ func ChooseOption(o *fs.Option, name string) string {
help = append(help, example.Help) help = append(help, example.Help)
} }
} }
in = Choose(o.Name, values, help, true) in = Choose(o.Name, values, help, !o.Exclusive)
} else { } else {
fmt.Printf("%s> ", o.Name) fmt.Printf("%s> ", o.Name)
in = ReadLine() in = ReadLine()

View File

@ -184,6 +184,7 @@ type Option struct {
IsPassword bool // set if the option is a password IsPassword bool // set if the option is a password
NoPrefix bool // set if the option for this should not use the backend prefix NoPrefix bool // set if the option for this should not use the backend prefix
Advanced bool // set if this is an advanced config option 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 // BaseOption is an alias for Option used internally

View File

@ -242,6 +242,7 @@ func TestOptionMarshalJSON(t *testing.T) {
"IsPassword": false, "IsPassword": false,
"NoPrefix": false, "NoPrefix": false,
"Advanced": true, "Advanced": true,
"Exclusive": false,
"DefaultStr": "false", "DefaultStr": "false",
"ValueStr": "true", "ValueStr": "true",
"Type": "bool" "Type": "bool"