fix(cli): treat eof as empty multi-select
All checks were successful
Security Scan / security (push) Successful in 20s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 06:20:30 +00:00
parent e96ea6d7c2
commit a035cb2169
2 changed files with 12 additions and 0 deletions

View file

@ -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
}

View file

@ -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)