Skip to content

Commit

Permalink
livepeer_cli: Improve user feedback when specifying numeric values fo…
Browse files Browse the repository at this point in the history
…r some wizard options (livepeer#2345)
  • Loading branch information
kparkins authored and ad-astra-video committed May 25, 2022
1 parent 8850898 commit 0e1912c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 4 additions & 6 deletions cmd/livepeer_cli/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"errors"
"fmt"
"github.com/livepeer/go-livepeer/build"
"io/ioutil"
"math/big"
"net/http"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions cmd/livepeer_cli/wizard_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.")
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/livepeer_cli/wizard_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())},
Expand All @@ -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())},
Expand Down
3 changes: 1 addition & 2 deletions cmd/livepeer_cli/wizard_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
3 changes: 1 addition & 2 deletions cmd/livepeer_cli/wizard_transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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. ")
}
Expand Down

0 comments on commit 0e1912c

Please sign in to comment.