Skip to content

fix(cli): select default option value #7152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cli/cliui/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,22 @@ type RichSelectOptions struct {
// RichSelect displays a list of user options including name and description.
func RichSelect(inv *clibase.Invocation, richOptions RichSelectOptions) (*codersdk.TemplateVersionParameterOption, error) {
opts := make([]string, len(richOptions.Options))
var defaultOpt string
for i, option := range richOptions.Options {
line := option.Name
if len(option.Description) > 0 {
line += ": " + option.Description
}
opts[i] = line

if option.Value == richOptions.Default {
defaultOpt = line
}
}

selected, err := Select(inv, SelectOptions{
Options: opts,
Default: richOptions.Default,
Default: defaultOpt,
Size: richOptions.Size,
HideSearch: richOptions.HideSearch,
})
Expand Down