aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/puppeth/wizard.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-12-03 22:50:59 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-12-04 18:12:40 +0800
commitd4415f5e40fbd155adb3e85e4eae5c7db7832694 (patch)
tree8488e9f090452b234a53e3dd346f2874f2bf0b57 /cmd/puppeth/wizard.go
parent8698fbabf6c7811e8eec6e84512510e9c9a4eb45 (diff)
downloaddexon-d4415f5e40fbd155adb3e85e4eae5c7db7832694.tar.gz
dexon-d4415f5e40fbd155adb3e85e4eae5c7db7832694.tar.zst
dexon-d4415f5e40fbd155adb3e85e4eae5c7db7832694.zip
cmd/puppeth: chain import/export via wizard, minor polishes
Diffstat (limited to 'cmd/puppeth/wizard.go')
-rw-r--r--cmd/puppeth/wizard.go56
1 files changed, 38 insertions, 18 deletions
diff --git a/cmd/puppeth/wizard.go b/cmd/puppeth/wizard.go
index 42fc125e5..83536506c 100644
--- a/cmd/puppeth/wizard.go
+++ b/cmd/puppeth/wizard.go
@@ -23,6 +23,7 @@ import (
"io/ioutil"
"math/big"
"net"
+ "net/url"
"os"
"path/filepath"
"sort"
@@ -104,40 +105,59 @@ func (w *wizard) readString() string {
}
}
-// readYesNo reads a yes or no from stdin, returning boolean true for yes
-func (w *wizard) readYesNo(def bool) bool {
+// readDefaultString reads a single line from stdin, trimming if from spaces. If
+// an empty line is entered, the default value is returned.
+func (w *wizard) readDefaultString(def string) string {
+ fmt.Printf("> ")
+ text, err := w.in.ReadString('\n')
+ if err != nil {
+ log.Crit("Failed to read user input", "err", err)
+ }
+ if text = strings.TrimSpace(text); text != "" {
+ return text
+ }
+ return def
+}
+
+// readDefaultYesNo reads a single line from stdin, trimming if from spaces and
+// interpreting it as a 'yes' or a 'no'. If an empty line is entered, the default
+// value is returned.
+func (w *wizard) readDefaultYesNo(def bool) bool {
for {
fmt.Printf("> ")
text, err := w.in.ReadString('\n')
if err != nil {
log.Crit("Failed to read user input", "err", err)
}
- text = strings.ToLower(strings.TrimSpace(text))
+ if text = strings.ToLower(strings.TrimSpace(text)); text == "" {
+ return def
+ }
if text == "y" || text == "yes" {
return true
}
if text == "n" || text == "no" {
return false
}
- if len(text) == 0 {
- return def
- }
- fmt.Println("Valid answers: y, yes, n, no or leave empty for default")
+ log.Error("Invalid input, expected 'y', 'yes', 'n', 'no' or empty")
}
}
-// readDefaultString reads a single line from stdin, trimming if from spaces. If
-// an empty line is entered, the default value is returned.
-func (w *wizard) readDefaultString(def string) string {
- fmt.Printf("> ")
- text, err := w.in.ReadString('\n')
- if err != nil {
- log.Crit("Failed to read user input", "err", err)
- }
- if text = strings.TrimSpace(text); text != "" {
- return text
+// readURL reads a single line from stdin, trimming if from spaces and trying to
+// interpret it as a URL (http, https or file).
+func (w *wizard) readURL() *url.URL {
+ for {
+ fmt.Printf("> ")
+ text, err := w.in.ReadString('\n')
+ if err != nil {
+ log.Crit("Failed to read user input", "err", err)
+ }
+ uri, err := url.Parse(strings.TrimSpace(text))
+ if err != nil {
+ log.Error("Invalid input, expected URL", "err", err)
+ continue
+ }
+ return uri
}
- return def
}
// readInt reads a single line from stdin, trimming if from spaces, enforcing it