From 083ca8234bd6717130da5d68b97ac73f1c606917 Mon Sep 17 00:00:00 2001 From: Jeremiah Andrews Date: Mon, 28 May 2018 15:00:37 -0700 Subject: [PATCH 1/9] Refactored gaiacli and gaiad commands into subcommands --- client/rpc/block.go | 2 +- client/rpc/root.go | 2 -- client/rpc/validators.go | 2 +- cmd/gaia/cmd/gaiacli/main.go | 60 ++++++++++++++++++++++++++++++------ cmd/gaia/cmd/gaiad/main.go | 1 + server/util.go | 19 ++++++++++-- 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/client/rpc/block.go b/client/rpc/block.go index 3547270197..36327a722a 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -16,7 +16,7 @@ const ( flagSelect = "select" ) -func blockCommand() *cobra.Command { +func BlockCommand() *cobra.Command { cmd := &cobra.Command{ Use: "block [height]", Short: "Get verified data for a the block at given height", diff --git a/client/rpc/root.go b/client/rpc/root.go index f779bd7292..e89972c3c7 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -26,8 +26,6 @@ func AddCommands(cmd *cobra.Command) { cmd.AddCommand( initClientCommand(), statusCommand(), - blockCommand(), - validatorCommand(), ) } diff --git a/client/rpc/validators.go b/client/rpc/validators.go index 892d131ac3..bfd8a9582b 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -14,7 +14,7 @@ import ( // TODO these next two functions feel kinda hacky based on their placement -func validatorCommand() *cobra.Command { +func ValidatorCommand() *cobra.Command { cmd := &cobra.Command{ Use: "validatorset [height]", Short: "Get the full validator set at given height", diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 51dab68e28..4f82d58ad3 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -35,31 +35,73 @@ func main() { // the below functions and eliminate global vars, like we do // with the cdc - // add standard rpc, and tx commands + // add standard rpc commands rpc.AddCommands(rootCmd) rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) - // add query/post commands (custom to binary) + //Add state commands + stateCmd := &cobra.Command{ + Use: "state", + Short: "State querying subcommands (validators, blocks, transactions)", + } + stateCmd.AddCommand( + rpc.BlockCommand(), + rpc.ValidatorCommand(), + ) + tx.AddCommands(stateCmd, cdc) rootCmd.AddCommand( + stateCmd, + client.LineBreak, + ) + + //Add stake commands + stakeCmd := &cobra.Command{ + Use: "stake", + Short: "Stake and validation subcommands", + } + stakeCmd.AddCommand( client.GetCommands( - authcmd.GetAccountCmd("acc", cdc, authcmd.GetAccountDecoder(cdc)), stakecmd.GetCmdQueryValidator("stake", cdc), stakecmd.GetCmdQueryValidators("stake", cdc), stakecmd.GetCmdQueryDelegation("stake", cdc), stakecmd.GetCmdQueryDelegations("stake", cdc), )...) - rootCmd.AddCommand( + stakeCmd.AddCommand( client.PostCommands( - bankcmd.SendTxCmd(cdc), - ibccmd.IBCTransferCmd(cdc), - ibccmd.IBCRelayCmd(cdc), stakecmd.GetCmdCreateValidator(cdc), stakecmd.GetCmdEditValidator(cdc), stakecmd.GetCmdDelegate(cdc), stakecmd.GetCmdUnbond(cdc), )...) + rootCmd.AddCommand( + stakeCmd, + client.LineBreak, + ) + + //Add IBC commands + ibcCmd := &cobra.Command{ + Use: "ibc", + Short: "Inter-Blockchain Communication subcommands", + } + ibcCmd.AddCommand( + client.PostCommands( + ibccmd.IBCTransferCmd(cdc), + ibccmd.IBCRelayCmd(cdc), + )...) + rootCmd.AddCommand( + ibcCmd, + client.LineBreak, + ) + + //Add auth and bank commands + rootCmd.AddCommand( + client.GetCommands( + authcmd.GetAccountCmd("acc", cdc, authcmd.GetAccountDecoder(cdc)), + )...) + rootCmd.AddCommand( + client.PostCommands( + bankcmd.SendTxCmd(cdc), + )...) // add proxy, version and key info rootCmd.AddCommand( diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index f64498d850..30cb276ee1 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -17,6 +17,7 @@ import ( func main() { cdc := app.MakeCodec() ctx := server.NewDefaultContext() + cobra.EnableCommandSorting = false rootCmd := &cobra.Command{ Use: "gaiad", Short: "Gaia Daemon (server)", diff --git a/server/util.go b/server/util.go index f44cc2d728..da43dabbb1 100644 --- a/server/util.go +++ b/server/util.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/wire" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" @@ -72,13 +73,25 @@ func AddCommands( rootCmd.PersistentFlags().String("log_level", ctx.Config.LogLevel, "Log level") - rootCmd.AddCommand( - InitCmd(ctx, cdc, appInit), - StartCmd(ctx, appCreator), + tendCmd := &cobra.Command{ + Use: "tendermint", + Short: "Tendermint subcommands", + } + + tendCmd.AddCommand( UnsafeResetAllCmd(ctx), ShowNodeIDCmd(ctx), ShowValidatorCmd(ctx), + ) + + rootCmd.AddCommand( + InitCmd(ctx, cdc, appInit), + StartCmd(ctx, appCreator), + client.LineBreak, + tendCmd, + client.LineBreak, ExportCmd(ctx, cdc, appExport), + client.LineBreak, version.VersionCmd, ) } From a032386e876cb652a27b5b5563afcea16f5b6e0f Mon Sep 17 00:00:00 2001 From: Jeremiah Andrews Date: Mon, 28 May 2018 15:50:07 -0700 Subject: [PATCH 2/9] Added comments to newly exported functions --- client/rpc/block.go | 1 + client/rpc/validators.go | 1 + 2 files changed, 2 insertions(+) diff --git a/client/rpc/block.go b/client/rpc/block.go index 36327a722a..693298bb86 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -16,6 +16,7 @@ const ( flagSelect = "select" ) +//BlockCommand returns the verified block data for a given heights func BlockCommand() *cobra.Command { cmd := &cobra.Command{ Use: "block [height]", diff --git a/client/rpc/validators.go b/client/rpc/validators.go index bfd8a9582b..e05d1c4348 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -14,6 +14,7 @@ import ( // TODO these next two functions feel kinda hacky based on their placement +//ValidatorCommand returns the validator set for a given height func ValidatorCommand() *cobra.Command { cmd := &cobra.Command{ Use: "validatorset [height]", From 744f78573ea90873a8f24cda9c0cb1f55049a81e Mon Sep 17 00:00:00 2001 From: Jeremiah Andrews Date: Thu, 31 May 2018 18:38:15 -0700 Subject: [PATCH 3/9] small fixes --- client/rpc/validators.go | 2 +- cmd/gaia/cmd/gaiacli/main.go | 43 +++++++++++++++++++----------------- server/util.go | 6 ++--- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/client/rpc/validators.go b/client/rpc/validators.go index e05d1c4348..27b7fce99e 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -18,7 +18,7 @@ import ( func ValidatorCommand() *cobra.Command { cmd := &cobra.Command{ Use: "validatorset [height]", - Short: "Get the full validator set at given height", + Short: "Get the full tendermint validator set at given height", Args: cobra.MaximumNArgs(1), RunE: printValidators, } diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 4f82d58ad3..136260c760 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -37,7 +37,6 @@ func main() { // add standard rpc commands rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) //Add state commands stateCmd := &cobra.Command{ @@ -49,8 +48,30 @@ func main() { rpc.ValidatorCommand(), ) tx.AddCommands(stateCmd, cdc) - rootCmd.AddCommand( + + //Add IBC commands + ibcCmd := &cobra.Command{ + Use: "ibc", + Short: "Inter-Blockchain Communication subcommands", + } + ibcCmd.AddCommand( + client.PostCommands( + ibccmd.IBCTransferCmd(cdc), + ibccmd.IBCRelayCmd(cdc), + )...) + + advancedCmd := &cobra.Command{ + Use: "advanced", + Short: "Advanced subcommands", + } + + advancedCmd.AddCommand( stateCmd, + ibcCmd, + lcd.ServeCommand(cdc), + ) + rootCmd.AddCommand( + advancedCmd, client.LineBreak, ) @@ -75,22 +96,6 @@ func main() { )...) rootCmd.AddCommand( stakeCmd, - client.LineBreak, - ) - - //Add IBC commands - ibcCmd := &cobra.Command{ - Use: "ibc", - Short: "Inter-Blockchain Communication subcommands", - } - ibcCmd.AddCommand( - client.PostCommands( - ibccmd.IBCTransferCmd(cdc), - ibccmd.IBCRelayCmd(cdc), - )...) - rootCmd.AddCommand( - ibcCmd, - client.LineBreak, ) //Add auth and bank commands @@ -105,8 +110,6 @@ func main() { // add proxy, version and key info rootCmd.AddCommand( - client.LineBreak, - lcd.ServeCommand(cdc), keys.Commands(), client.LineBreak, version.VersionCmd, diff --git a/server/util.go b/server/util.go index da43dabbb1..93dc73469f 100644 --- a/server/util.go +++ b/server/util.go @@ -73,12 +73,12 @@ func AddCommands( rootCmd.PersistentFlags().String("log_level", ctx.Config.LogLevel, "Log level") - tendCmd := &cobra.Command{ + tendermintCmd := &cobra.Command{ Use: "tendermint", Short: "Tendermint subcommands", } - tendCmd.AddCommand( + tendermintCmd.AddCommand( UnsafeResetAllCmd(ctx), ShowNodeIDCmd(ctx), ShowValidatorCmd(ctx), @@ -88,7 +88,7 @@ func AddCommands( InitCmd(ctx, cdc, appInit), StartCmd(ctx, appCreator), client.LineBreak, - tendCmd, + tendermintCmd, client.LineBreak, ExportCmd(ctx, cdc, appExport), client.LineBreak, From aa41cefb1ee73dc7aede05879fbb3698d6a07c33 Mon Sep 17 00:00:00 2001 From: Jeremiah Andrews Date: Thu, 31 May 2018 18:51:06 -0700 Subject: [PATCH 4/9] renamed state subcommand to tendermint --- cmd/gaia/cmd/gaiacli/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 136260c760..049c07b364 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -39,15 +39,15 @@ func main() { rpc.AddCommands(rootCmd) //Add state commands - stateCmd := &cobra.Command{ - Use: "state", - Short: "State querying subcommands (validators, blocks, transactions)", + tendermintCmd := &cobra.Command{ + Use: "tendermint", + Short: "Tendermint state querying subcommands", } - stateCmd.AddCommand( + tendermintCmd.AddCommand( rpc.BlockCommand(), rpc.ValidatorCommand(), ) - tx.AddCommands(stateCmd, cdc) + tx.AddCommands(tendermintCmd, cdc) //Add IBC commands ibcCmd := &cobra.Command{ @@ -66,7 +66,7 @@ func main() { } advancedCmd.AddCommand( - stateCmd, + tendermintCmd, ibcCmd, lcd.ServeCommand(cdc), ) From a03638d14af144ef252239e7175c31e425bf2040 Mon Sep 17 00:00:00 2001 From: Jeremiah Andrews Date: Thu, 31 May 2018 22:06:13 -0700 Subject: [PATCH 5/9] changed commands in cli_test to match refactor --- cmd/gaia/cli_test/cli_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 8fa0ad71ec..3ed5a1f4bc 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -22,7 +22,7 @@ import ( func TestGaiaCLISend(t *testing.T) { - tests.ExecuteT(t, "gaiad unsafe_reset_all") + tests.ExecuteT(t, "gaiad tendermint unsafe_reset_all") pass := "1234567890" executeWrite(t, "gaiacli keys delete foo", pass) executeWrite(t, "gaiacli keys delete bar", pass) @@ -69,7 +69,7 @@ func TestGaiaCLISend(t *testing.T) { func TestGaiaCLICreateValidator(t *testing.T) { - tests.ExecuteT(t, "gaiad unsafe_reset_all") + tests.ExecuteT(t, "gaiad tendermint unsafe_reset_all") pass := "1234567890" executeWrite(t, "gaiacli keys delete foo", pass) executeWrite(t, "gaiacli keys delete bar", pass) @@ -104,7 +104,7 @@ func TestGaiaCLICreateValidator(t *testing.T) { assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak")) // create validator - cvStr := fmt.Sprintf("gaiacli create-validator %v", flags) + cvStr := fmt.Sprintf("gaiacli stake create-validator %v", flags) cvStr += fmt.Sprintf(" --name=%v", "bar") cvStr += fmt.Sprintf(" --address-validator=%v", barCech) cvStr += fmt.Sprintf(" --pubkey=%v", barCeshPubKey) @@ -117,12 +117,12 @@ func TestGaiaCLICreateValidator(t *testing.T) { barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak"), "%v", barAcc) - validator := executeGetValidator(t, fmt.Sprintf("gaiacli validator %v --output=json %v", barCech, flags)) + validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags)) assert.Equal(t, validator.Owner, barAddr) assert.Equal(t, "2/1", validator.PoolShares.Amount.String()) // unbond a single share - unbondStr := fmt.Sprintf("gaiacli unbond %v", flags) + unbondStr := fmt.Sprintf("gaiacli stake unbond %v", flags) unbondStr += fmt.Sprintf(" --name=%v", "bar") unbondStr += fmt.Sprintf(" --address-validator=%v", barCech) unbondStr += fmt.Sprintf(" --address-delegator=%v", barCech) @@ -135,7 +135,7 @@ func TestGaiaCLICreateValidator(t *testing.T) { barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) require.Equal(t, int64(9), barAcc.GetCoins().AmountOf("steak"), "%v", barAcc) - validator = executeGetValidator(t, fmt.Sprintf("gaiacli validator %v --output=json %v", barCech, flags)) + validator = executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %v --output=json %v", barCech, flags)) assert.Equal(t, "1/1", validator.PoolShares.Amount.String()) } From 7ce9e000b62403cc58b00ac98f465658153c7d52 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 1 Jun 2018 00:53:54 -0700 Subject: [PATCH 6/9] update changelog, minor update --- CHANGELOG.md | 1 + server/util.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 037cf63078..e23165799f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Pending BREAKING CHANGES +* [cli] rearranged commands under subcommands FEATURES diff --git a/server/util.go b/server/util.go index 93dc73469f..9c251aa4ce 100644 --- a/server/util.go +++ b/server/util.go @@ -89,7 +89,6 @@ func AddCommands( StartCmd(ctx, appCreator), client.LineBreak, tendermintCmd, - client.LineBreak, ExportCmd(ctx, cdc, appExport), client.LineBreak, version.VersionCmd, From 34686e8d61d25c04e82c46d57e433879e8091945 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 1 Jun 2018 01:35:39 -0700 Subject: [PATCH 7/9] unsafe_reset_all back to root --- server/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index 9c251aa4ce..9e705f8792 100644 --- a/server/util.go +++ b/server/util.go @@ -79,7 +79,6 @@ func AddCommands( } tendermintCmd.AddCommand( - UnsafeResetAllCmd(ctx), ShowNodeIDCmd(ctx), ShowValidatorCmd(ctx), ) @@ -87,6 +86,7 @@ func AddCommands( rootCmd.AddCommand( InitCmd(ctx, cdc, appInit), StartCmd(ctx, appCreator), + UnsafeResetAllCmd(ctx), client.LineBreak, tendermintCmd, ExportCmd(ctx, cdc, appExport), From 823814dfce1c4e7051a7dbc470cc4f5de348cfc1 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 1 Jun 2018 01:47:44 -0700 Subject: [PATCH 8/9] fix cli test --- cmd/gaia/cli_test/cli_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 3ed5a1f4bc..f6dc50d43b 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -22,7 +22,7 @@ import ( func TestGaiaCLISend(t *testing.T) { - tests.ExecuteT(t, "gaiad tendermint unsafe_reset_all") + tests.ExecuteT(t, "gaiad unsafe_reset_all") pass := "1234567890" executeWrite(t, "gaiacli keys delete foo", pass) executeWrite(t, "gaiacli keys delete bar", pass) @@ -69,7 +69,7 @@ func TestGaiaCLISend(t *testing.T) { func TestGaiaCLICreateValidator(t *testing.T) { - tests.ExecuteT(t, "gaiad tendermint unsafe_reset_all") + tests.ExecuteT(t, "gaiad unsafe_reset_all") pass := "1234567890" executeWrite(t, "gaiacli keys delete foo", pass) executeWrite(t, "gaiacli keys delete bar", pass) From e1d9f00d2de4aa9c24111975b2538be753b9ac5e Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 1 Jun 2018 01:57:21 -0700 Subject: [PATCH 9/9] ... --- cmd/gaia/cli_test/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index f6dc50d43b..a591c9903f 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -96,7 +96,7 @@ func TestGaiaCLICreateValidator(t *testing.T) { require.NoError(t, err) executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barCech), pass) - time.Sleep(time.Second * 2) // waiting for some blocks to pass + time.Sleep(time.Second * 3) // waiting for some blocks to pass barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags)) assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak"))