@@ -2,11 +2,16 @@ package common
22
33import (
44 "fmt"
5+ "os"
56
67 "github.com/AlecAivazis/survey/v2"
78 "github.com/spf13/cobra"
89)
910
11+ // StdioOpts returns survey options for using stderr for prompts.
12+ // This ensures prompts are visible even when stdout is piped.
13+ var StdioOpts = survey .WithStdio (os .Stdin , os .Stderr , os .Stderr )
14+
1015var (
1116 // PromptPassphrase is the standard passphrase prompt.
1217 PromptPassphrase = & survey.Password {
@@ -27,12 +32,12 @@ var (
2732// Confirm asks the user for confirmation and aborts when rejected.
2833func Confirm (msg , abortMsg string ) {
2934 if answerYes {
30- fmt .Printf ( "? %s Yes\n " , msg )
35+ fmt .Fprintf ( os . Stderr , "? %s Yes\n " , msg )
3136 return
3237 }
3338
3439 var proceed bool
35- err := survey .AskOne (& survey.Confirm {Message : msg }, & proceed )
40+ err := survey .AskOne (& survey.Confirm {Message : msg }, & proceed , StdioOpts )
3641 cobra .CheckErr (err )
3742 if ! proceed {
3843 cobra .CheckErr (abortMsg )
@@ -61,7 +66,7 @@ func AskNewPassphrase() string {
6166 },
6267 },
6368 }
64- err := survey .Ask (questions , & answers )
69+ err := survey .Ask (questions , & answers , StdioOpts )
6570 cobra .CheckErr (err )
6671
6772 return answers .Passphrase
0 commit comments