diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 31ebb8c77b..3857919e91 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -21,6 +21,9 @@ ### Bug Fixes 🐞 +#### CLI +- \#2345 Improve user feedback when specifying numeric values for some wizard options (@kparkins) + #### General - \#2299 Split devtool Orchestrator run scripts into versions with/without external transcoder and prevent Transcoder/Broadcaster run scripts from using same CLI port (@thomshutt) diff --git a/cmd/livepeer_cli/wizard.go b/cmd/livepeer_cli/wizard.go index 6758c25feb..2ccc6be8a5 100644 --- a/cmd/livepeer_cli/wizard.go +++ b/cmd/livepeer_cli/wizard.go @@ -5,7 +5,6 @@ import ( "bytes" "errors" "fmt" - "github.com/livepeer/go-livepeer/build" "io/ioutil" "math/big" "net/http" @@ -14,6 +13,8 @@ import ( "strconv" "strings" + "github.com/livepeer/go-livepeer/build" + "github.com/ethereum/go-ethereum/log" lpcommon "github.com/livepeer/go-livepeer/common" "github.com/livepeer/go-livepeer/eth" @@ -161,16 +162,13 @@ func (w *wizard) readDefaultInt(def int) int { return def } -func (w *wizard) readBigInt() *big.Int { +func (w *wizard) readBigInt(prompt string) *big.Int { for { - fmt.Printf("> ") + fmt.Printf(fmt.Sprintf("%s - > ", prompt)) text, err := w.in.ReadString('\n') if err != nil { log.Crit("Failed to read user input", "err", err) } - if text = strings.TrimSpace(text); text == "" { - continue - } val, err := lpcommon.ParseBigInt(strings.TrimSpace(text)) if err != nil { log.Error("Invalid input, expected big integer", "err", err) diff --git a/cmd/livepeer_cli/wizard_bond.go b/cmd/livepeer_cli/wizard_bond.go index c8f06c351f..6d45f2f8bc 100644 --- a/cmd/livepeer_cli/wizard_bond.go +++ b/cmd/livepeer_cli/wizard_bond.go @@ -165,8 +165,7 @@ func (w *wizard) bond() { amount := big.NewInt(0) for amount.Cmp(big.NewInt(0)) == 0 || balBigInt.Cmp(amount) < 0 { - fmt.Printf("Enter bond amount - ") - amount = w.readBigInt() + amount = w.readBigInt("Enter bond amount") if amount.Cmp(big.NewInt(0)) == 0 { break } @@ -277,8 +276,7 @@ func (w *wizard) unbond() { } for amount.Cmp(big.NewInt(0)) == 0 || dInfo.BondedAmount.Cmp(amount) < 0 { - fmt.Printf("Enter unbond amount - ") - amount = w.readBigInt() + amount = w.readBigInt("Enter unbond amount") if dInfo.BondedAmount.Cmp(amount) < 0 { fmt.Printf("Must enter an amount less than or equal to the current bonded amount.") } diff --git a/cmd/livepeer_cli/wizard_eth.go b/cmd/livepeer_cli/wizard_eth.go index 77b95b9664..6f8a1e85b7 100644 --- a/cmd/livepeer_cli/wizard_eth.go +++ b/cmd/livepeer_cli/wizard_eth.go @@ -7,8 +7,7 @@ import ( func (w *wizard) setMaxGasPrice() { fmt.Printf("Current maximum gas price: %v\n", w.maxGasPrice()) - fmt.Printf("Enter new maximum gas price in Wei (enter \"0\" for no maximum gas price)") - amount := w.readBigInt() + amount := w.readBigInt("Enter new maximum gas price in Wei (enter \"0\" for no maximum gas price)") val := url.Values{ "amount": {fmt.Sprintf("%v", amount.String())}, @@ -19,8 +18,7 @@ func (w *wizard) setMaxGasPrice() { func (w *wizard) setMinGasPrice() { fmt.Printf("Current minimum gas price: %v\n", w.minGasPrice()) - fmt.Printf("Enter new minimum gas price in Wei") - minGasPrice := w.readBigInt() + minGasPrice := w.readBigInt("Enter new minimum gas price in Wei") val := url.Values{ "minGasPrice": {fmt.Sprintf("%v", minGasPrice.String())}, diff --git a/cmd/livepeer_cli/wizard_token.go b/cmd/livepeer_cli/wizard_token.go index 5228f90e9d..a2aa38b299 100644 --- a/cmd/livepeer_cli/wizard_token.go +++ b/cmd/livepeer_cli/wizard_token.go @@ -12,8 +12,7 @@ func (w *wizard) transferTokens() { fmt.Printf("Enter receipient address (in hex i.e. 0xfoo) - ") to := w.readString() - fmt.Printf("Enter amount - ") - amount := w.readBigInt() + amount := w.readBigInt("Enter amount") val := url.Values{ "to": {fmt.Sprintf("%v", to)}, diff --git a/cmd/livepeer_cli/wizard_transcoder.go b/cmd/livepeer_cli/wizard_transcoder.go index 12c7b121e8..a4cd94673c 100644 --- a/cmd/livepeer_cli/wizard_transcoder.go +++ b/cmd/livepeer_cli/wizard_transcoder.go @@ -143,8 +143,7 @@ func (w *wizard) activateOrchestrator() { amount := big.NewInt(0) for amount.Cmp(big.NewInt(0)) == 0 || balBigInt.Cmp(amount) < 0 { - fmt.Printf("Enter bond amount - ") - amount = w.readBigInt() + amount = w.readBigInt("Enter bond amount") if balBigInt.Cmp(amount) < 0 { fmt.Printf("Must enter an amount smaller than the current balance. ") }