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",
Help: "No",
}},
Exclusive: true,
},
}, nil
}
@ -185,6 +186,7 @@ func ConfigChooseFixed(state string, name string, help string, items []OptionExa
Name: name,
Help: help,
Examples: items,
Exclusive: true,
},
}
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)
}
}
in = Choose(o.Name, values, help, true)
in = Choose(o.Name, values, help, !o.Exclusive)
} else {
fmt.Printf("%s> ", o.Name)
in = ReadLine()

View File

@ -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

View File

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