From b1850124de3787346ff7446641efff9ab9b43b0c Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 04:36:07 +0000 Subject: [PATCH] fix(cli): accept comma-separated multi-select input --- pkg/cli/prompt_test.go | 16 ++++++++++++++++ pkg/cli/utils.go | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/cli/prompt_test.go b/pkg/cli/prompt_test.go index b2c27c1..d40d7d5 100644 --- a/pkg/cli/prompt_test.go +++ b/pkg/cli/prompt_test.go @@ -91,6 +91,22 @@ func TestChooseMulti_Good_Filter(t *testing.T) { assert.Equal(t, []string{"apple", "apricot"}, vals) } +func TestChooseMulti_Good_Commas(t *testing.T) { + SetStdin(strings.NewReader("1,3\n")) + defer SetStdin(nil) + + vals := ChooseMulti("Pick", []string{"a", "b", "c"}) + assert.Equal(t, []string{"a", "c"}, vals) +} + +func TestChooseMulti_Good_CommasAndRanges(t *testing.T) { + SetStdin(strings.NewReader("1-2,4\n")) + defer SetStdin(nil) + + vals := ChooseMulti("Pick", []string{"a", "b", "c", "d"}) + assert.Equal(t, []string{"a", "b", "d"}, vals) +} + func TestSetStdin_Good_ResetNil(t *testing.T) { original := stdin t.Cleanup(func() { stdin = original }) diff --git a/pkg/cli/utils.go b/pkg/cli/utils.go index 4698283..c0fea5c 100644 --- a/pkg/cli/utils.go +++ b/pkg/cli/utils.go @@ -503,12 +503,15 @@ func looksLikeMultiSelectionInput(input string) bool { return hasDigit } -// parseMultiSelection parses a multi-selection string like "1 3 5" or "1-3 5". +// parseMultiSelection parses a multi-selection string like "1 3 5", "1,3,5", +// or "1-3 5". // Returns 0-based indices. func parseMultiSelection(input string, maxItems int) ([]int, error) { selected := make(map[int]bool) - for part := range strings.FieldsSeq(input) { + normalized := strings.NewReplacer(",", " ").Replace(input) + + for part := range strings.FieldsSeq(normalized) { // Check for range (e.g., "1-3") if strings.Contains(part, "-") { var rangeParts []string