From 231a5b35ab75e198eeefb275a7baf65308e81e0c Mon Sep 17 00:00:00 2001 From: Artur Albov Date: Thu, 27 Sep 2018 14:14:44 +0300 Subject: [PATCH] Cosmos POC: Clean up CLI --- cosmos/poc/commands/getlinks.go | 4 +-- cosmos/poc/cyberdcli/main.go | 48 ++++++++++++--------------------- cosmos/poc/go.sum | 1 + 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/cosmos/poc/commands/getlinks.go b/cosmos/poc/commands/getlinks.go index 47ca83f4..5a81d532 100644 --- a/cosmos/poc/commands/getlinks.go +++ b/cosmos/poc/commands/getlinks.go @@ -11,7 +11,7 @@ import ( // GetAccountCmd returns a query account that will display the state of the // account at a given address. -func GetLinksCmd(cdc *wire.Codec) *cobra.Command { +func GetLinksCmd(storeName string, cdc *wire.Codec) *cobra.Command { return &cobra.Command{ Use: "links [cid]", Short: "Query cid links", @@ -27,7 +27,7 @@ func GetLinksCmd(cdc *wire.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) - res, err := cliCtx.QueryStore(key, "link") + res, err := cliCtx.QueryStore(key, storeName) if err != nil || len(res) == 0 { return err } diff --git a/cosmos/poc/cyberdcli/main.go b/cosmos/poc/cyberdcli/main.go index 100dff47..3f25eb51 100644 --- a/cosmos/poc/cyberdcli/main.go +++ b/cosmos/poc/cyberdcli/main.go @@ -8,22 +8,20 @@ import ( "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cybercongress/cyberd/cosmos/poc/app" "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" + "github.com/cybercongress/cyberd/cosmos/poc/app" cyberdcmd "github.com/cybercongress/cyberd/cosmos/poc/commands" - ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" - stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" "github.com/spf13/cobra" "github.com/tendermint/tendermint/libs/cli" ) -// rootCmd is the entry point for this binary +// cyberdcli is the entry point for this binary var ( - rootCmd = &cobra.Command{ + cyberdcli = &cobra.Command{ Use: "cyberdcli", - Short: "Cyberd light-client", + Short: "Cyberd node client", } ) @@ -38,46 +36,34 @@ func main() { // the below functions and eliminate global vars, like we do // with the cdc. - // add standard rpc, and tx commands - rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) + rpc.AddCommands(cyberdcli) // Node management commands + cyberdcli.AddCommand(client.LineBreak) + tx.AddCommands(cyberdcli, cdc) // Txs info commands + cyberdcli.AddCommand(client.LineBreak) + cyberdcli.AddCommand(rpc.BlockCommand()) // Block info command + cyberdcli.AddCommand(client.LineBreak) - // add query/post commands (custom to binary) - rootCmd.AddCommand( + cyberdcli.AddCommand( client.GetCommands( - stakecmd.GetCmdQueryValidator("stake", cdc), - stakecmd.GetCmdQueryValidators("stake", cdc), - stakecmd.GetCmdQueryDelegation("stake", cdc), - stakecmd.GetCmdQueryDelegations("stake", cdc), authcmd.GetAccountCmd("acc", cdc, app.GetAccountDecoder(cdc)), - cyberdcmd.GetLinksCmd(cdc), + cyberdcmd.GetLinksCmd("link", cdc), )...) - rootCmd.AddCommand( + cyberdcli.AddCommand( client.PostCommands( cyberdcmd.LinkTxCmd(cdc), bankcmd.SendTxCmd(cdc), - ibccmd.IBCTransferCmd(cdc), - ibccmd.IBCRelayCmd(cdc), - stakecmd.GetCmdCreateValidator(cdc), - stakecmd.GetCmdEditValidator(cdc), - stakecmd.GetCmdDelegate(cdc), - stakecmd.GetCmdUnbond("stake", cdc), )...) - // add proxy, version and key info - rootCmd.AddCommand( + cyberdcli.AddCommand( client.LineBreak, - lcd.ServeCommand(cdc), - keys.Commands(), + lcd.ServeCommand(cdc), // Commands to start local rpc proxy to node + keys.Commands(), // Commands to generate and handle keys client.LineBreak, version.VersionCmd, ) - // prepare and add flags - executor := cli.PrepareMainCmd(rootCmd, "CBD", os.ExpandEnv("$HOME/.cyberdcli")) + executor := cli.PrepareMainCmd(cyberdcli, "CBD", os.ExpandEnv("$HOME/.cyberdcli")) err := executor.Execute() if err != nil { // Note: Handle with #870 diff --git a/cosmos/poc/go.sum b/cosmos/poc/go.sum index 24635fdc..62441b09 100644 --- a/cosmos/poc/go.sum +++ b/cosmos/poc/go.sum @@ -13,6 +13,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cosmos/cosmos-sdk v0.24.2 h1:4NbgiXVPKjBpJRkZ1LnMxaz6EV+OCguFXy9Y+rT5ItY= github.com/cosmos/cosmos-sdk v0.24.2/go.mod h1:JrX/JpJunJQXBI5PEX2zELHMFzQr/159jDjIhesOh2c= github.com/cybercongress/cyberd v0.0.0-20180924154316-73930bbeebb1 h1:q4NHkuD56j5pUzyvjVWo1qELi6gKyB7cts7wb2bwxL0= +github.com/cybercongress/cyberd v0.0.0-20180925174400-fc51a4a10dbc h1:Jf8Skbd5z0NPwTGKYcZRHJot3DCwKhKhxvKElDsO7oA= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/ebuchman/fail-test v0.0.0-20170303061230-95f809107225 h1:7TXT8REobzZUI9GzsRtAD29efTY/HgKRU2xYnV1zlaM=