Reorganize CLI command structure. Fixes #2575

This commit is contained in:
Jack Zampolin 2018-11-07 15:03:00 -08:00
parent 8f690b5b6c
commit d4fb6d4ebe
8 changed files with 193 additions and 111 deletions

View File

@ -22,15 +22,7 @@ func todoNotImplemented(_ *cobra.Command, _ []string) error {
return errors.New("todo: Command not yet implemented") return errors.New("todo: Command not yet implemented")
} }
// AddCommands adds a number of rpc-related subcommands func InitClientCommand() *cobra.Command {
func AddCommands(cmd *cobra.Command) {
cmd.AddCommand(
initClientCommand(),
statusCommand(),
)
}
func initClientCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "init", Use: "init",
Short: "Initialize light client", Short: "Initialize light client",

View File

@ -14,7 +14,8 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
) )
func statusCommand() *cobra.Command { // StatusCommand returns the status of the network
func StatusCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "status", Use: "status",
Short: "Query remote node for status", Short: "Query remote node for status",

View File

@ -2,20 +2,11 @@ package tx
import ( import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
) )
// AddCommands adds a number of tx-query related subcommands
func AddCommands(cmd *cobra.Command, cdc *codec.Codec) {
cmd.AddCommand(
SearchTxCmd(cdc),
QueryTxCmd(cdc),
)
}
// register REST routes // register REST routes
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET")

View File

@ -13,18 +13,10 @@ import (
"github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app" "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik" _ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
) )
@ -40,7 +32,7 @@ const (
var ( var (
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
Use: "gaiacli", Use: "gaiacli",
Short: "Gaia light-client", Short: "Command line interface for interacting with gaiad",
} }
) )
@ -57,90 +49,23 @@ func main() {
// TODO: setup keybase, viper object, etc. to be passed into // TODO: setup keybase, viper object, etc. to be passed into
// the below functions and eliminate global vars, like we do // the below functions and eliminate global vars, like we do
// with the cdc // with the cdc
rootCmd.AddCommand(client.ConfigCmd())
// add standard rpc commands // Consturct Root Command
rpc.AddCommands(rootCmd)
//Add query commands
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
}
queryCmd.AddCommand(
rpc.BlockCommand(),
rpc.ValidatorCommand(),
)
tx.AddCommands(queryCmd, cdc)
queryCmd.AddCommand(client.LineBreak)
queryCmd.AddCommand(client.GetCommands(
authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)),
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
stakecmd.GetCmdQueryValidator(storeStake, cdc),
stakecmd.GetCmdQueryValidators(storeStake, cdc),
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
stakecmd.GetCmdQueryParams(storeStake, cdc),
stakecmd.GetCmdQueryPool(storeStake, cdc),
govcmd.GetCmdQueryProposal(storeGov, cdc),
govcmd.GetCmdQueryProposals(storeGov, cdc),
govcmd.GetCmdQueryVote(storeGov, cdc),
govcmd.GetCmdQueryVotes(storeGov, cdc),
govcmd.GetCmdQueryDeposit(storeGov, cdc),
govcmd.GetCmdQueryDeposits(storeGov, cdc),
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
)...)
//Add query commands
txCmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
}
//Add auth and bank commands
txCmd.AddCommand(
client.PostCommands(
bankcmd.GetBroadcastCommand(cdc),
authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)),
)...)
txCmd.AddCommand(client.LineBreak)
txCmd.AddCommand(
client.PostCommands(
stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdRedelegate(storeStake, cdc),
stakecmd.GetCmdUnbond(storeStake, cdc),
distrcmd.GetCmdWithdrawRewards(cdc),
distrcmd.GetCmdSetWithdrawAddr(cdc),
govcmd.GetCmdDeposit(cdc),
bankcmd.SendTxCmd(cdc),
govcmd.GetCmdSubmitProposal(cdc),
slashingcmd.GetCmdUnjail(cdc),
govcmd.GetCmdVote(cdc),
)...)
rootCmd.AddCommand( rootCmd.AddCommand(
queryCmd, rpc.InitClientCommand(),
txCmd, rpc.StatusCommand(),
client.ConfigCmd(),
queryCmd(cdc),
txCmd(cdc),
client.LineBreak,
lcd.ServeCommand(cdc), lcd.ServeCommand(cdc),
client.LineBreak, client.LineBreak,
)
// add proxy, version and key info
rootCmd.AddCommand(
keys.Commands(), keys.Commands(),
client.LineBreak, client.LineBreak,
version.VersionCmd, version.VersionCmd,
) )
// prepare and add flags // Add flags and prefix all env exposed with GA
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome) executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome)
err := initConfig(rootCmd) err := initConfig(rootCmd)
if err != nil { if err != nil {

View File

@ -0,0 +1,81 @@
package main
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
amino "github.com/tendermint/go-amino"
)
func queryCmd(cdc *amino.Codec) *cobra.Command {
//Add query commands
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
}
// Group staking queries under a subcommand
stakeQueryCmd := &cobra.Command{
Use: "stake",
Short: "Querying commands for staking module",
}
stakeQueryCmd.AddCommand(client.GetCommands(
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
stakecmd.GetCmdQueryValidator(storeStake, cdc),
stakecmd.GetCmdQueryValidators(storeStake, cdc),
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
stakecmd.GetCmdQueryParams(storeStake, cdc),
stakecmd.GetCmdQueryPool(storeStake, cdc))...)
// Group gov queries under a subcommand
govQueryCmd := &cobra.Command{
Use: "gov",
Short: "Querying commands for gov module",
}
govQueryCmd.AddCommand(client.GetCommands(
govcmd.GetCmdQueryProposal(storeGov, cdc),
govcmd.GetCmdQueryProposals(storeGov, cdc),
govcmd.GetCmdQueryVote(storeGov, cdc),
govcmd.GetCmdQueryVotes(storeGov, cdc),
govcmd.GetCmdQueryDeposit(storeGov, cdc),
govcmd.GetCmdQueryDeposits(storeGov, cdc))...)
// Group slashing queries under a subcommand
slashingQueryCmd := &cobra.Command{
Use: "slashing",
Short: "Querying commands for slashing module",
}
slashingQueryCmd.AddCommand(client.GetCommands(
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc))...)
// Query commcmmand sturcture
queryCmd.AddCommand(
rpc.BlockCommand(),
rpc.ValidatorCommand(),
tx.SearchTxCmd(cdc),
tx.QueryTxCmd(cdc),
client.LineBreak,
authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)),
stakeQueryCmd,
govQueryCmd,
slashingQueryCmd,
)
return queryCmd
}

View File

@ -0,0 +1,83 @@
package main
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
amino "github.com/tendermint/go-amino"
)
func txCmd(cdc *amino.Codec) *cobra.Command {
//Add transaction generation commands
txCmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
}
stakeTxCmd := &cobra.Command{
Use: "stake",
Short: "Stake Transactions subcommands",
}
stakeTxCmd.AddCommand(client.PostCommands(
stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdRedelegate(storeStake, cdc),
stakecmd.GetCmdUnbond(storeStake, cdc),
)...)
distTxCmd := &cobra.Command{
Use: "dist",
Short: "Distribution Transactions subcommands",
}
distTxCmd.AddCommand(client.PostCommands(
distrcmd.GetCmdWithdrawRewards(cdc),
distrcmd.GetCmdSetWithdrawAddr(cdc),
)...)
govTxCmd := &cobra.Command{
Use: "gov",
Short: "Governance Transactions subcommands",
}
govTxCmd.AddCommand(client.PostCommands(
govcmd.GetCmdDeposit(cdc),
govcmd.GetCmdVote(cdc),
govcmd.GetCmdSubmitProposal(cdc),
)...)
slashingTxCmd := &cobra.Command{
Use: "slashing",
Short: "Slashing Transactions subcommands",
}
slashingTxCmd.AddCommand(client.PostCommands(
slashingcmd.GetCmdUnjail(cdc),
)...)
txCmd.AddCommand(
//Add auth and bank commands
client.PostCommands(
bankcmd.SendTxCmd(cdc),
bankcmd.GetBroadcastCommand(cdc),
authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)),
)...)
txCmd.AddCommand(
client.LineBreak,
stakeTxCmd,
distTxCmd,
govTxCmd,
slashingTxCmd,
)
return txCmd
}

View File

@ -39,10 +39,14 @@ func main() {
// with the cdc. // with the cdc.
// add standard rpc, and tx commands // add standard rpc, and tx commands
rpc.AddCommands(rootCmd) rootCmd.AddCommand(
rootCmd.AddCommand(client.LineBreak) rpc.InitClientCommand(),
tx.AddCommands(rootCmd, cdc) rpc.StatusCommand(),
rootCmd.AddCommand(client.LineBreak) client.LineBreak,
tx.SearchTxCmd(cdc),
tx.QueryTxCmd(cdc),
client.LineBreak,
)
// add query/post commands (custom to binary) // add query/post commands (custom to binary)
rootCmd.AddCommand( rootCmd.AddCommand(

View File

@ -52,10 +52,15 @@ func main() {
// with the cdc // with the cdc
// add standard rpc, and tx commands // add standard rpc, and tx commands
rpc.AddCommands(rootCmd)
rootCmd.AddCommand(client.LineBreak) rootCmd.AddCommand(
tx.AddCommands(rootCmd, cdc) rpc.InitClientCommand(),
rootCmd.AddCommand(client.LineBreak) rpc.StatusCommand(),
client.LineBreak,
tx.SearchTxCmd(cdc),
tx.QueryTxCmd(cdc),
client.LineBreak,
)
// add query/post commands (custom to binary) // add query/post commands (custom to binary)
// start with commands common to basecoin // start with commands common to basecoin