fix(cli): send prompt recovery hints to stderr

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 10:56:52 +00:00
parent 32b824a8a4
commit 8a7567c705
2 changed files with 30 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package cli
import (
"bytes"
"io"
"os"
"strings"
@ -272,3 +273,29 @@ func TestSetStdin_Good_ResetNil(t *testing.T) {
SetStdin(nil)
assert.Same(t, os.Stdin, stdin)
}
func TestPromptHints_Good_UseStderr(t *testing.T) {
oldOut := os.Stdout
oldErr := os.Stderr
rOut, wOut, _ := os.Pipe()
rErr, wErr, _ := os.Pipe()
os.Stdout = wOut
os.Stderr = wErr
promptHint("try again")
promptWarning("invalid")
_ = wOut.Close()
_ = wErr.Close()
os.Stdout = oldOut
os.Stderr = oldErr
var stdout bytes.Buffer
var stderr bytes.Buffer
_, _ = io.Copy(&stdout, rOut)
_, _ = io.Copy(&stderr, rErr)
assert.Empty(t, stdout.String())
assert.Contains(t, stderr.String(), "try again")
assert.Contains(t, stderr.String(), "invalid")
}

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"time"
@ -39,11 +40,11 @@ type confirmConfig struct {
}
func promptHint(msg string) {
fmt.Println(DimStyle.Render(compileGlyphs(msg)))
fmt.Fprintln(os.Stderr, DimStyle.Render(compileGlyphs(msg)))
}
func promptWarning(msg string) {
fmt.Println(WarningStyle.Render(compileGlyphs(msg)))
fmt.Fprintln(os.Stderr, WarningStyle.Render(compileGlyphs(msg)))
}
// DefaultYes sets the default response to "yes" (pressing Enter confirms).