Skip to content

feat: implement rich multi-selector #19201

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 6 commits into from
Aug 6, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
mtojek committed Aug 6, 2025
commit e71c7f389da6e1695c461b871e96886a586b10df
26 changes: 21 additions & 5 deletions cli/cliui/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,30 @@
opts := make([]string, len(richOptions.Options))
var defaultOpts []string

for i, option := range richOptions.Options {
asLine := func(option codersdk.TemplateVersionParameterOption) string {
line := option.Name
if len(option.Description) > 0 {
line += ": " + option.Description
}
opts[i] = line
return line
}

var predefinedOpts []string
for i, option := range richOptions.Options {
opts[i] = asLine(option) // Some options may have description defined.

// Check if option is selected by default
if slices.Contains(richOptions.Defaults, option.Value) {
defaultOpts = append(defaultOpts, line)
defaultOpts = append(defaultOpts, opts[i])
predefinedOpts = append(predefinedOpts, option.Value)
}
}

// Check if "defaults" contains extra/custom options, user could select them.
for _, def := range richOptions.Defaults {
if !slices.Contains(predefinedOpts, def) {
opts = append(opts, def)

Check failure on line 336 in cli/cliui/select.go

View workflow job for this annotation

GitHub Actions / lint

append to slice `opts` with non-zero initialized length (makezero)
defaultOpts = append(defaultOpts, def)
}
}

Expand All @@ -333,11 +348,12 @@
return nil, err
}

// Check selected option, convert descriptions (line) to values
var results []string
for _, sel := range selected {
custom := true
for i, option := range opts {
if option == sel {
for i, option := range richOptions.Options {
if asLine(option) == sel {
results = append(results, richOptions.Options[i].Value)
custom = false
break
Expand Down
Loading