@@ -2,11 +2,25 @@ package common
22
33import (
44 "fmt"
5+ "os"
56
67 "github.com/AlecAivazis/survey/v2"
78 "github.com/spf13/cobra"
89)
910
11+ // SurveyStdio is the standard survey option to direct prompts to stderr.
12+ var SurveyStdio = survey .WithStdio (os .Stdin , os .Stderr , os .Stderr )
13+
14+ // Ask wraps survey.AskOne while forcing prompts to stderr.
15+ func Ask (p survey.Prompt , response interface {}, opts ... survey.AskOpt ) error {
16+ return survey .AskOne (p , response , append ([]survey.AskOpt {SurveyStdio }, opts ... )... )
17+ }
18+
19+ // AskMulti wraps survey.Ask while forcing prompts to stderr.
20+ func AskMulti (qs []* survey.Question , response interface {}, opts ... survey.AskOpt ) error {
21+ return survey .Ask (qs , response , append ([]survey.AskOpt {SurveyStdio }, opts ... )... )
22+ }
23+
1024var (
1125 // PromptPassphrase is the standard passphrase prompt.
1226 PromptPassphrase = & survey.Password {
@@ -27,12 +41,12 @@ var (
2741// Confirm asks the user for confirmation and aborts when rejected.
2842func Confirm (msg , abortMsg string ) {
2943 if answerYes {
30- fmt .Printf ( "? %s Yes\n " , msg )
44+ fmt .Fprintf ( os . Stderr , "? %s Yes\n " , msg )
3145 return
3246 }
3347
3448 var proceed bool
35- err := survey . AskOne (& survey.Confirm {Message : msg }, & proceed )
49+ err := Ask (& survey.Confirm {Message : msg }, & proceed )
3650 cobra .CheckErr (err )
3751 if ! proceed {
3852 cobra .CheckErr (abortMsg )
@@ -61,7 +75,7 @@ func AskNewPassphrase() string {
6175 },
6276 },
6377 }
64- err := survey . Ask (questions , & answers )
78+ err := AskMulti (questions , & answers )
6579 cobra .CheckErr (err )
6680
6781 return answers .Passphrase
0 commit comments