mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
fix: select default option value (#7152)
This commit is contained in:
@ -70,17 +70,22 @@ type RichSelectOptions struct {
|
|||||||
// RichSelect displays a list of user options including name and description.
|
// RichSelect displays a list of user options including name and description.
|
||||||
func RichSelect(inv *clibase.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error) {
|
func RichSelect(inv *clibase.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error) {
|
||||||
opts := make([]string, len(richOptions.Options))
|
opts := make([]string, len(richOptions.Options))
|
||||||
|
var defaultOpt string
|
||||||
for i, option := range richOptions.Options {
|
for i, option := range richOptions.Options {
|
||||||
line := option.Name
|
line := option.Name
|
||||||
if len(option.Description) > 0 {
|
if len(option.Description) > 0 {
|
||||||
line += ": " + option.Description
|
line += ": " + option.Description
|
||||||
}
|
}
|
||||||
opts[i] = line
|
opts[i] = line
|
||||||
|
|
||||||
|
if option.Value == richOptions.Default {
|
||||||
|
defaultOpt = line
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selected, err := Select(inv, SelectOptions{
|
selected, err := Select(inv, SelectOptions{
|
||||||
Options: opts,
|
Options: opts,
|
||||||
Default: richOptions.Default,
|
Default: defaultOpt,
|
||||||
Size: richOptions.Size,
|
Size: richOptions.Size,
|
||||||
HideSearch: richOptions.HideSearch,
|
HideSearch: richOptions.HideSearch,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user