Skip to content

Commit 5516a8b

Browse files
committed
Fix piping for commands needin wallet unlock
1 parent f1b6275 commit 5516a8b

27 files changed

+37
-5
lines changed

cmd/common/prompts.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package common
22

33
import (
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+
1015
var (
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.
2833
func 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

cmd/common/wallet.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67

78
"github.com/AlecAivazis/survey/v2"
@@ -61,9 +62,10 @@ func LoadAccount(cfg *config.Config, name string) wallet.Account {
6162
var passphrase string
6263
if af.RequiresPassphrase() && !answerYes {
6364
// Ask for passphrase to decrypt the account.
64-
fmt.Printf("Unlock your account.\n")
65+
// Use stderr for prompts so they work when stdout is piped.
66+
fmt.Fprintln(os.Stderr, "Unlock your account.")
6567

66-
err = survey.AskOne(PromptPassphrase, &passphrase)
68+
err = survey.AskOne(PromptPassphrase, &passphrase, StdioOpts)
6769
cobra.CheckErr(err)
6870
}
6971

examples/account/allow-paratime.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Fee:
1212
Network: testnet
1313
ParaTime: none (consensus layer)
1414
Account: oscar
15+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/allow.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Fee:
1212
Network: testnet
1313
ParaTime: none (consensus layer)
1414
Account: oscar
15+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/amend-commission-schedule.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Fee:
2121
Network: testnet
2222
ParaTime: none (consensus layer)
2323
Account: oscar
24+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/burn.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Fee:
1111
Network: testnet
1212
ParaTime: none (consensus layer)
1313
Account: oscar
14+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/delegate-paratime.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Fee:
1515
Network: testnet
1616
ParaTime: sapphire
1717
Account: oscar
18+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/delegate.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Fee:
1212
Network: testnet
1313
ParaTime: none (consensus layer)
1414
Account: oscar
15+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/deposit-eth.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Fee:
1515
Network: testnet
1616
ParaTime: sapphire
1717
Account: oscar
18+
(In case you are using a hardware-based signer you may need to confirm on device.)

examples/account/deposit-named.y.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Fee:
1515
Network: testnet
1616
ParaTime: sapphire
1717
Account: oscar
18+
(In case you are using a hardware-based signer you may need to confirm on device.)

0 commit comments

Comments
 (0)