Skip to content

Commit c1a13ce

Browse files
authored
feat(cmd): read password from file (#1653)
1 parent b403dac commit c1a13ce

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/daemon/start.go

+11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"os"
55
"path/filepath"
6+
"strings"
67

78
"github.com/gofrs/flock"
89
"github.com/pactus-project/pactus/cmd"
10+
"github.com/pactus-project/pactus/util"
911
"github.com/pactus-project/pactus/wallet"
1012
"github.com/spf13/cobra"
1113
)
@@ -24,6 +26,9 @@ func buildStartCmd(parentCmd *cobra.Command) {
2426
passwordOpt := startCmd.Flags().StringP("password", "p", "",
2527
"the wallet password")
2628

29+
passwordFromFileOpt := startCmd.Flags().String("password-from-file", "",
30+
"the file containing the wallet password")
31+
2732
startCmd.Run = func(_ *cobra.Command, _ []string) {
2833
workingDir, _ := filepath.Abs(*workingDirOpt)
2934
// change working directory
@@ -49,8 +54,14 @@ func buildStartCmd(parentCmd *cobra.Command) {
4954
}
5055

5156
var password string
57+
5258
if *passwordOpt != "" {
5359
password = *passwordOpt
60+
} else if *passwordFromFileOpt != "" {
61+
b, err := util.ReadFile(*passwordFromFileOpt)
62+
cmd.FatalErrorCheck(err)
63+
64+
password = strings.TrimSpace(string(b))
5465
} else {
5566
password = cmd.PromptPassword("Wallet password", false)
5667
}

0 commit comments

Comments
 (0)