Skip to content

Commit

Permalink
Refactored gaiacli and gaiad commands into subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
UnitylChaos committed Jun 1, 2018
1 parent 9f8c5ad commit 083ca82
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions client/rpc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func AddCommands(cmd *cobra.Command) {
cmd.AddCommand(
initClientCommand(),
statusCommand(),
blockCommand(),
validatorCommand(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
60 changes: 51 additions & 9 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
19 changes: 16 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
}
Expand Down

0 comments on commit 083ca82

Please sign in to comment.