From 8a7567c70545e74ba01da6b62b867c0c11c98e1b Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 10:56:52 +0000 Subject: [PATCH] fix(cli): send prompt recovery hints to stderr Co-Authored-By: Virgil --- pkg/cli/prompt_test.go | 27 +++++++++++++++++++++++++++ pkg/cli/utils.go | 5 +++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pkg/cli/prompt_test.go b/pkg/cli/prompt_test.go index c7cf643..07bdd78 100644 --- a/pkg/cli/prompt_test.go +++ b/pkg/cli/prompt_test.go @@ -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") +} diff --git a/pkg/cli/utils.go b/pkg/cli/utils.go index c60da07..8d749d4 100644 --- a/pkg/cli/utils.go +++ b/pkg/cli/utils.go @@ -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). -- 2.45.3