Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/cli/RFC.md fully. Find features des...' (#73) from agent/read---spec-code-core-go-cli-rfc-md-full into dev
Some checks failed
Security Scan / security (push) Has been cancelled
Some checks failed
Security Scan / security (push) Has been cancelled
This commit is contained in:
commit
5e663d6d94
2 changed files with 21 additions and 5 deletions
|
|
@ -42,11 +42,18 @@ func Prompt(label, defaultVal string) (string, error) {
|
|||
|
||||
r := newReader()
|
||||
input, err := r.ReadString('\n')
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
input = strings.TrimSpace(input)
|
||||
if err != nil {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
input = strings.TrimSpace(input)
|
||||
if input == "" {
|
||||
if defaultVal != "" {
|
||||
return defaultVal, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if input == "" {
|
||||
return defaultVal, nil
|
||||
}
|
||||
|
|
@ -68,7 +75,7 @@ func Select(label string, options []string) (string, error) {
|
|||
r := newReader()
|
||||
input, err := r.ReadString('\n')
|
||||
if err != nil && strings.TrimSpace(input) == "" {
|
||||
return "", err
|
||||
return "", fmt.Errorf("selection cancelled: %w", err)
|
||||
}
|
||||
|
||||
trimmed := strings.TrimSpace(input)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,15 @@ func TestPrompt_Bad_EOFUsesDefault(t *testing.T) {
|
|||
assert.Equal(t, "world", val)
|
||||
}
|
||||
|
||||
func TestPrompt_Bad_EOFWithoutDefaultReturnsError(t *testing.T) {
|
||||
SetStdin(strings.NewReader(""))
|
||||
defer SetStdin(nil)
|
||||
|
||||
val, err := Prompt("Name", "")
|
||||
assert.ErrorIs(t, err, io.EOF)
|
||||
assert.Empty(t, val)
|
||||
}
|
||||
|
||||
func TestSelect_Good(t *testing.T) {
|
||||
SetStdin(strings.NewReader("2\n"))
|
||||
defer SetStdin(nil)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue