From bb7b49de6af0df99772d20e72d869f96a7b0862e Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Thu, 29 Jan 2026 14:40:02 +0100 Subject: [PATCH] fix(cli): ignore space in custom input mode (#21752) Fixes: https://github.com/coder/internal/issues/560 "Select" CLI UI component should ignore "space" when `+Add custom value` is highlighted. Otherwise it interprets that as a potential option... and panics. --- cli/cliui/select.go | 5 +++++ cli/exp_prompts.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cli/cliui/select.go b/cli/cliui/select.go index f609ca81c3..8ef4c0e4ba 100644 --- a/cli/cliui/select.go +++ b/cli/cliui/select.go @@ -491,6 +491,11 @@ func (m multiSelectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.KeySpace: options := m.filteredOptions() + + if m.enableCustomInput && m.cursor == len(options) { + return m, nil + } + if len(options) != 0 { options[m.cursor].chosen = !options[m.cursor].chosen } diff --git a/cli/exp_prompts.go b/cli/exp_prompts.go index ef51a1ce04..a100068f22 100644 --- a/cli/exp_prompts.go +++ b/cli/exp_prompts.go @@ -174,6 +174,19 @@ func (RootCmd) promptExample() *serpent.Command { _, _ = fmt.Fprintf(inv.Stdout, "%q are nice choices.\n", strings.Join(multiSelectValues, ", ")) return multiSelectError }, useThingsOption, enableCustomInputOption), + promptCmd("multi-select-no-defaults", func(inv *serpent.Invocation) error { + if len(multiSelectValues) == 0 { + multiSelectValues, multiSelectError = cliui.MultiSelect(inv, cliui.MultiSelectOptions{ + Message: "Select some things:", + Options: []string{ + "Code", "Chairs", "Whale", + }, + EnableCustomInput: enableCustomInput, + }) + } + _, _ = fmt.Fprintf(inv.Stdout, "%q are nice choices.\n", strings.Join(multiSelectValues, ", ")) + return multiSelectError + }, useThingsOption, enableCustomInputOption), promptCmd("rich-multi-select", func(inv *serpent.Invocation) error { if len(multiSelectValues) == 0 { multiSelectValues, multiSelectError = cliui.MultiSelect(inv, cliui.MultiSelectOptions{