From a035cb21690785496dd23b142e2c30576b5ff977 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 06:20:30 +0000 Subject: [PATCH] fix(cli): treat eof as empty multi-select Co-Authored-By: Virgil --- pkg/cli/prompt.go | 3 +++ pkg/cli/prompt_test.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/cli/prompt.go b/pkg/cli/prompt.go index 7e7ebe4..0b1aa7f 100644 --- a/pkg/cli/prompt.go +++ b/pkg/cli/prompt.go @@ -84,6 +84,9 @@ func MultiSelect(label string, options []string) ([]string, error) { r := newReader() input, err := r.ReadString('\n') + if err != nil && strings.TrimSpace(input) == "" { + return []string{}, nil + } if err != nil { return nil, err } diff --git a/pkg/cli/prompt_test.go b/pkg/cli/prompt_test.go index d793e16..9ffc0bc 100644 --- a/pkg/cli/prompt_test.go +++ b/pkg/cli/prompt_test.go @@ -79,6 +79,15 @@ func TestMultiSelect_Good_CommasAndRanges(t *testing.T) { assert.Equal(t, []string{"a", "b", "d"}, vals) } +func TestMultiSelect_Bad_EOFReturnsEmptySelection(t *testing.T) { + SetStdin(strings.NewReader("")) + defer SetStdin(nil) + + vals, err := MultiSelect("Pick", []string{"a", "b", "c"}) + assert.NoError(t, err) + assert.Empty(t, vals) +} + func TestConfirm_Good(t *testing.T) { SetStdin(strings.NewReader("y\n")) defer SetStdin(nil)