From 63d166d1021c64a41837b69898086108a5ea8f3f Mon Sep 17 00:00:00 2001 From: Itay Date: Mon, 3 Jul 2023 17:47:57 +0300 Subject: [PATCH] feat: Add loading spinner with status on roller init, register and run (#166) --- cmd/config/init/init.go | 12 +++++++++--- cmd/consts/consts.go | 8 ++++++++ cmd/register/register.go | 12 +++++++++++- cmd/run/run.go | 10 ++++++++-- cmd/utils/output.go | 6 ++++++ go.mod | 3 ++- go.sum | 4 ++++ 7 files changed, 48 insertions(+), 7 deletions(-) diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index cbb57cb7..064324ef 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -2,12 +2,11 @@ package initconfig import ( "fmt" - "os" - "github.com/cosmos/cosmos-sdk/types/errors" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/spf13/cobra" + "os" ) const validDenomMsg = "A valid denom should consist of exactly 3 English alphabet letters, for example 'btc', 'eth'" @@ -46,6 +45,9 @@ func InitCmd() *cobra.Command { return nil }, Run: func(cmd *cobra.Command, args []string) { + spin := utils.GetLoadingSpinner() + spin.Suffix = consts.SpinnerMsgs.UniqueIdVerification + spin.Start() initConfig, err := GetInitConfig(cmd, args) utils.PrettifyErrorIfExists(err) @@ -57,6 +59,7 @@ func InitCmd() *cobra.Command { isRootExist, err := dirNotEmpty(initConfig.Home) utils.PrettifyErrorIfExists(err) if isRootExist { + spin.Stop() shouldOverwrite, err := promptOverwriteConfig(initConfig.Home) utils.PrettifyErrorIfExists(err) if shouldOverwrite { @@ -64,11 +67,13 @@ func InitCmd() *cobra.Command { } else { os.Exit(0) } + spin.Start() } utils.PrettifyErrorIfExists(os.MkdirAll(initConfig.Home, 0755)) //TODO: create all dirs here - + spin.Suffix = " Initializing RollApp configuration files..." + spin.Restart() /* ---------------------------- Initilize relayer --------------------------- */ utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{ ID: initConfig.RollappID, @@ -101,6 +106,7 @@ func InitCmd() *cobra.Command { utils.PrettifyErrorIfExists(utils.WriteConfigToTOML(initConfig)) /* ------------------------------ Print output ------------------------------ */ + spin.Stop() printInitOutput(initConfig, addresses, initConfig.RollappID) }, } diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 8cf630e5..73952cc9 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -97,3 +97,11 @@ const ( // TODO: Check DA LC write price on arabica and update this value. var OneDAWritePrice = big.NewInt(1) + +var SpinnerMsgs = struct { + UniqueIdVerification string + BalancesVerification string +}{ + UniqueIdVerification: " Verifying unique RollApp ID...\n", + BalancesVerification: " Verifying balances...\n", +} diff --git a/cmd/register/register.go b/cmd/register/register.go index dcdcc601..1e7c9aa6 100644 --- a/cmd/register/register.go +++ b/cmd/register/register.go @@ -4,8 +4,8 @@ import ( "bytes" "errors" "fmt" + "github.com/dymensionxyz/roller/cmd/consts" "math/big" - "strings" "encoding/json" @@ -23,18 +23,28 @@ func Cmd() *cobra.Command { Use: "register", Short: "Registers the rollapp and the sequencer to the Dymension hub.", Run: func(cmd *cobra.Command, args []string) { + spin := utils.GetLoadingSpinner() + spin.Suffix = consts.SpinnerMsgs.BalancesVerification + spin.Start() home := cmd.Flag(utils.FlagNames.Home).Value.String() rollappConfig, err := utils.LoadConfigFromTOML(home) utils.PrettifyErrorIfExists(err) notFundedAddrs, err := utils.GetSequencerInsufficientAddrs(rollappConfig, *registerUdymPrice) utils.PrettifyErrorIfExists(err) utils.PrintInsufficientBalancesIfAny(notFundedAddrs) + spin.Suffix = consts.SpinnerMsgs.UniqueIdVerification + spin.Restart() utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig)) + spin.Suffix = " Registering RollApp to hub...\n" + spin.Restart() utils.PrettifyErrorIfExists(registerRollapp(rollappConfig)) registerSequencerCmd, err := getRegisterSequencerCmd(rollappConfig) utils.PrettifyErrorIfExists(err) + spin.Suffix = " Registering RollApp sequencer...\n" + spin.Restart() _, err = utils.ExecBashCommand(registerSequencerCmd) utils.PrettifyErrorIfExists(err) + spin.Stop() printRegisterOutput(rollappConfig) }, } diff --git a/cmd/run/run.go b/cmd/run/run.go index 5a829288..7e1adc17 100644 --- a/cmd/run/run.go +++ b/cmd/run/run.go @@ -19,6 +19,9 @@ func Cmd() *cobra.Command { Use: "run", Short: "Runs the rollapp on the local machine.", Run: func(cmd *cobra.Command, args []string) { + spin := utils.GetLoadingSpinner() + spin.Suffix = consts.SpinnerMsgs.BalancesVerification + spin.Start() home := cmd.Flag(utils.FlagNames.Home).Value.String() rollappConfig, err := utils.LoadConfigFromTOML(home) utils.PrettifyErrorIfExists(err) @@ -32,14 +35,17 @@ func Cmd() *cobra.Command { Context: ctx, WaitGroup: &waitingGroup, } + spin.Suffix = " Starting RollApp services..." + spin.Restart() runDaWithRestarts(rollappConfig, serviceConfig) runSequencerWithRestarts(rollappConfig, serviceConfig) runRelayerWithRestarts(rollappConfig, serviceConfig) PrintServicesStatus(rollappConfig) cancel() - logger.Println("Killing subprocesses") + spin.Suffix = " Killing subprocesses..." + spin.Restart() waitingGroup.Wait() - logger.Println("killed them") + spin.Stop() }, } diff --git a/cmd/utils/output.go b/cmd/utils/output.go index 0aede7ab..58311cfe 100644 --- a/cmd/utils/output.go +++ b/cmd/utils/output.go @@ -3,9 +3,11 @@ package utils import ( "errors" "fmt" + "github.com/briandowns/spinner" "github.com/olekukonko/tablewriter" "math/big" "os" + "time" ) func PrintInsufficientBalancesIfAny(addressesData []NotFundedAddressData) { @@ -44,3 +46,7 @@ type NotFundedAddressData struct { RequiredBalance *big.Int Denom string } + +func GetLoadingSpinner() *spinner.Spinner { + return spinner.New(spinner.CharSets[9], 100*time.Millisecond) +} diff --git a/go.mod b/go.mod index 81cc1781..093208c4 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/armon/go-metrics v0.4.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect + github.com/briandowns/spinner v1.23.0 // indirect github.com/btcsuite/btcd v0.22.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect @@ -105,7 +106,7 @@ require ( golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect golang.org/x/sys v0.6.0 // indirect - golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect + golang.org/x/term v0.1.0 // indirect golang.org/x/text v0.4.0 // indirect google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect google.golang.org/grpc v1.51.0 // indirect diff --git a/go.sum b/go.sum index 17391a76..12c1de08 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A= +github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE= github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= @@ -679,6 +681,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=