From cfe31c409023536bfe29eafbb0fff0a0d56dc893 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Sat, 18 May 2019 19:06:08 -0400 Subject: [PATCH] Merge PR #4372: Use Build's Client/Server Name --- server/util.go | 4 +- version/command.go | 62 ++++++------- version/version.go | 49 ++++++---- x/auth/client/cli/multisign.go | 14 ++- x/distribution/client/cli/query.go | 47 +++++++--- x/distribution/client/cli/tx.go | 40 +++++--- x/gov/client/cli/query.go | 130 +++++++++++++++++--------- x/gov/client/cli/tx.go | 45 ++++++--- x/params/client/cli/tx.go | 19 ++-- x/staking/client/cli/query.go | 144 +++++++++++++++++++++-------- x/staking/client/cli/tx.go | 40 +++++--- 11 files changed, 398 insertions(+), 196 deletions(-) diff --git a/server/util.go b/server/util.go index 8874c5045..938949299 100644 --- a/server/util.go +++ b/server/util.go @@ -51,7 +51,7 @@ func NewContext(config *cfg.Config, logger log.Logger) *Context { // logger and config object. func PersistentPreRunEFn(context *Context) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { - if cmd.Name() == version.VersionCmd.Name() { + if cmd.Name() == version.Cmd.Name() { return nil } config, err := interceptLoadConfig() @@ -152,7 +152,7 @@ func AddCommands( tendermintCmd, ExportCmd(ctx, cdc, appExport), client.LineBreak, - version.VersionCmd, + version.Cmd, ) } diff --git a/version/command.go b/version/command.go index b886a9f24..703dda192 100644 --- a/version/command.go +++ b/version/command.go @@ -10,40 +10,34 @@ import ( "github.com/tendermint/tendermint/libs/cli" ) -const ( - flagLong = "long" -) - -var ( - - // VersionCmd prints out the application's version - // information passed via build flags. - VersionCmd = &cobra.Command{ - Use: "version", - Short: "Print the app version", - RunE: func(_ *cobra.Command, _ []string) error { - verInfo := newVersionInfo() - - if !viper.GetBool(flagLong) { - fmt.Println(verInfo.Version) - return nil - } - - if viper.GetString(cli.OutputFlag) != "json" { - fmt.Println(verInfo) - return nil - } - - bz, err := json.Marshal(verInfo) - if err != nil { - return err - } - fmt.Println(string(bz)) - return nil - }, - } -) +const flagLong = "long" func init() { - VersionCmd.Flags().Bool(flagLong, false, "Print long version information") + Cmd.Flags().Bool(flagLong, false, "Print long version information") +} + +// Cmd prints out the application's version information passed via build flags. +var Cmd = &cobra.Command{ + Use: "version", + Short: "Print the app version", + RunE: func(_ *cobra.Command, _ []string) error { + verInfo := newVersionInfo() + + if !viper.GetBool(flagLong) { + fmt.Println(verInfo.Version) + return nil + } + + if viper.GetString(cli.OutputFlag) != "json" { + fmt.Println(verInfo) + return nil + } + + bz, err := json.Marshal(verInfo) + if err != nil { + return err + } + fmt.Println(string(bz)) + return nil + }, } diff --git a/version/version.go b/version/version.go index 86274dfea..234c249f1 100644 --- a/version/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ -// This package is a convenience utility that provides SDK +// Package version is a convenience utility that provides SDK // consumers with a ready-to-use version command that // produces apps versioning information based on flags // passed at compile time. @@ -9,7 +9,9 @@ // At build time, the variables Name, Version, Commit, and BuildTags // can be passed as build flags as shown in the following example: // -// go build -X github.com/cosmos/cosmos-sdk/version.Name=dapp \ +// go build -X github.com/cosmos/cosmos-sdk/version.Name=gaia \ +// -X github.com/cosmos/cosmos-sdk/version.ServerName=gaiad \ +// -X github.com/cosmos/cosmos-sdk/version.ClientName=gaiacli \ // -X github.com/cosmos/cosmos-sdk/version.Version=1.0 \ // -X github.com/cosmos/cosmos-sdk/version.Commit=f0f7b7dab7e36c20b757cebce0e8f4fc5b95de60 \ // -X "github.com/cosmos/cosmos-sdk/version.BuildTags=linux darwin amd64" @@ -21,38 +23,49 @@ import ( ) var ( - // Application's name + // application's name Name = "" - // Application's version string + // server binary name + ServerName = "" + // client binary name + ClientName = "" + // application's version string Version = "" - // Commit + // commit Commit = "" - // Hash of the go.sum file + // hash of the go.sum file GoSumHash = "" - // Build tags + // build tags BuildTags = "" ) type versionInfo struct { - Name string `json:"name"` - Version string `json:"version"` - GitCommit string `json:"commit"` - BuildTags string `json:"build_tags"` - GoVersion string `json:"go"` + Name string `json:"name"` + ServerName string `json:"server_name"` + ClientName string `json:"client_name"` + Version string `json:"version"` + GitCommit string `json:"commit"` + BuildTags string `json:"build_tags"` + GoVersion string `json:"go"` } func (v versionInfo) String() string { return fmt.Sprintf(`%s: %s git commit: %s build tags: %s -%s`, v.Name, v.Version, v.GitCommit, v.BuildTags, v.GoVersion) +%s`, + v.Name, v.Version, v.GitCommit, v.BuildTags, v.GoVersion, + ) } func newVersionInfo() versionInfo { return versionInfo{ - Name, - Version, - Commit, - BuildTags, - fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)} + Name: Name, + ServerName: ServerName, + ClientName: ClientName, + Version: Version, + GitCommit: Commit, + BuildTags: BuildTags, + GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH), + } } diff --git a/x/auth/client/cli/multisign.go b/x/auth/client/cli/multisign.go index 5b3b6450b..b1aa98fd5 100644 --- a/x/auth/client/cli/multisign.go +++ b/x/auth/client/cli/multisign.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -16,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/utils" crkeys "github.com/cosmos/cosmos-sdk/crypto/keys" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" ) @@ -25,12 +27,14 @@ func GetMultiSignCommand(codec *amino.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "multisign [file] [name] [[signature]...]", Short: "Generate multisig signatures for transactions generated offline", - Long: `Sign transactions created with the --generate-only flag that require multisig signatures. + Long: strings.TrimSpace( + fmt.Sprintf(`Sign transactions created with the --generate-only flag that require multisig signatures. Read signature(s) from [signature] file(s), generate a multisig signature compliant to the -multisig key [name], and attach it to the transaction read from [file]. Example: +multisig key [name], and attach it to the transaction read from [file]. - multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json +Example: +$ %s multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json If the flag --signature-only flag is on, it outputs a JSON representation of the generated signature only. @@ -39,9 +43,13 @@ The --offline flag makes sure that the client will not reach out to an external Thus account number or sequence number lookups will not be performed and it is recommended to set such parameters manually. `, + version.ClientName, + ), + ), RunE: makeMultiSignCmd(codec), Args: cobra.MinimumNArgs(3), } + cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().Bool(flagOffline, false, "Offline mode. Do not query a full node") cmd.Flags().String(flagOutfile, "", "The document will be written to the given file instead of STDOUT") diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index 455f7d12d..0013d3d08 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/distribution/client/common" "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -60,10 +61,15 @@ func GetCmdQueryValidatorCommission(queryRoute string, cdc *codec.Codec) *cobra. Use: "commission [validator]", Args: cobra.ExactArgs(1), Short: "Query distribution validator commission", - Long: strings.TrimSpace(`Query validator commission rewards from delegators to that validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query validator commission rewards from delegators to that validator. -$ query distr commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query distr commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -90,10 +96,15 @@ func GetCmdQueryValidatorSlashes(queryRoute string, cdc *codec.Codec) *cobra.Com Use: "slashes [validator] [start-height] [end-height]", Args: cobra.ExactArgs(3), Short: "Query distribution validator slashes", - Long: strings.TrimSpace(`Query all slashes of a validator for a given block range: + Long: strings.TrimSpace( + fmt.Sprintf(`Query all slashes of a validator for a given block range. -$ query distr slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 0 100 -`), +Example: +$ %s query distr slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 0 100 +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -136,11 +147,16 @@ func GetCmdQueryDelegatorRewards(queryRoute string, cdc *codec.Codec) *cobra.Com Use: "rewards [delegator-addr] []", Args: cobra.RangeArgs(1, 2), Short: "Query all distribution delegator rewards or rewards from a particular validator", - Long: strings.TrimSpace(`Query all rewards earned by a delegator, optionally restrict to rewards from a single validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query all rewards earned by a delegator, optionally restrict to rewards from a single validator. -$ query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p -$ query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p +$ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -175,10 +191,15 @@ func GetCmdQueryCommunityPool(queryRoute string, cdc *codec.Codec) *cobra.Comman Use: "community-pool", Args: cobra.NoArgs, Short: "Query the amount of coins in the community pool", - Long: strings.TrimSpace(`Query all coins in the community pool which is under Governance control. + Long: strings.TrimSpace( + fmt.Sprintf(`Query all coins in the community pool which is under Governance control. -$ query distr community-pool -`), +Example: +$ %s query distr community-pool +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index d69556d42..b101693e8 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -2,6 +2,7 @@ package cli import ( + "fmt" "strings" "github.com/spf13/cobra" @@ -13,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/utils" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/distribution/client/common" @@ -44,12 +46,18 @@ func GetTxCmd(storeKey string, cdc *amino.Codec) *cobra.Command { func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "withdraw-rewards [validator-addr]", - Short: "witdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", - Long: strings.TrimSpace(`witdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator: + Short: "Withdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw rewards from a given delegation address, +and optionally withdraw validator commission if the delegation address given is a validator operator. -$ tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey -$ tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --commission -`), +Example: +$ %s tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey +$ %s tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --commission +`, + version.ClientName, version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) @@ -80,10 +88,15 @@ func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Comman return &cobra.Command{ Use: "withdraw-all-rewards", Short: "withdraw all delegations rewards for a delegator", - Long: strings.TrimSpace(`Withdraw all rewards for a single delegator: + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw all rewards for a single delegator. -$ tx distr withdraw-all-rewards --from mykey -`), +Example: +$ %s tx distr withdraw-all-rewards --from mykey +`, + version.ClientName, + ), + ), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { @@ -108,10 +121,15 @@ func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "set-withdraw-addr [withdraw-addr]", Short: "change the default withdraw address for rewards associated with an address", - Long: strings.TrimSpace(`Set the withdraw address for rewards associated with a delegator address: + Long: strings.TrimSpace( + fmt.Sprintf(`Set the withdraw address for rewards associated with a delegator address. -$ tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey -`), +Example: +$ %s tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index e782eec1c..fcb0eb636 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/gov" gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" ) @@ -21,11 +22,16 @@ func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "proposal [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query details of a single proposal", - Long: strings.TrimSpace(` -Query details for a proposal. You can find the proposal-id by running query gov proposals: + Long: strings.TrimSpace( + fmt.Sprintf(`Query details for a proposal. You can find the +proposal-id by running "%s query gov proposals". -$ query gov proposal 1 -`), +Example: +$ %s query gov proposal 1 +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -53,13 +59,17 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "proposals", Short: "Query proposals with optional filters", - Long: strings.TrimSpace(` -Query for a all proposals. You can filter the returns with the following flags: + Long: strings.TrimSpace( + fmt.Sprintf(`Query for a all proposals. You can filter the returns with the following flags. -$ query gov proposals --depositor cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -$ query gov proposals --voter cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -$ query gov proposals --status (DepositPeriod|VotingPeriod|Passed|Rejected) -`), +Example: +$ %s query gov proposals --depositor cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk +$ %s query gov proposals --voter cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk +$ %s query gov proposals --status (DepositPeriod|VotingPeriod|Passed|Rejected) +`, + version.ClientName, version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { bechDepositorAddr := viper.GetString(flagDepositor) bechVoterAddr := viper.GetString(flagVoter) @@ -137,12 +147,15 @@ func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "vote [proposal-id] [voter-addr]", Args: cobra.ExactArgs(2), Short: "Query details of a single vote", - Long: strings.TrimSpace(` -Query details for a single vote on a proposal given its identifier. + Long: strings.TrimSpace( + fmt.Sprintf(`Query details for a single vote on a proposal given its identifier. Example: -$ query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -`), +$ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -200,12 +213,15 @@ func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "votes [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query votes on a proposal", - Long: strings.TrimSpace(` -Query vote details for a single proposal by its identifier. + Long: strings.TrimSpace( + fmt.Sprintf(`Query vote details for a single proposal by its identifier. Example: -$ query gov votes 1 -`), +$ %s query gov votes 1 +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -255,12 +271,15 @@ func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "deposit [proposal-id] [depositer-addr]", Args: cobra.ExactArgs(2), Short: "Query details of a deposit", - Long: strings.TrimSpace(` -Query details for a single proposal deposit on a proposal by its identifier. + Long: strings.TrimSpace( + fmt.Sprintf(`Query details for a single proposal deposit on a proposal by its identifier. Example: -$ query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -`), +$ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -314,11 +333,16 @@ func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "deposits [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query deposits on a proposal", - Long: strings.TrimSpace(` -Query details for all deposits on a proposal. You can find the proposal-id by running query gov proposals: + Long: strings.TrimSpace( + fmt.Sprintf(`Query details for all deposits on a proposal. +You can find the proposal-id by running "%s query gov proposals". -$ query gov deposits 1 -`), +Example: +$ %s query gov deposits 1 +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -337,7 +361,7 @@ $ query gov deposits 1 // check to see if the proposal is in the store res, err := gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute) if err != nil { - return fmt.Errorf("Failed to fetch proposal with id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal with id %d: %s", proposalID, err) } var proposal gov.Proposal @@ -367,11 +391,16 @@ func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "tally [proposal-id]", Args: cobra.ExactArgs(1), Short: "Get the tally of a proposal vote", - Long: strings.TrimSpace(` -Query tally of votes on a proposal. You can find the proposal-id by running query gov proposals: + Long: strings.TrimSpace( + fmt.Sprintf(`Query tally of votes on a proposal. You can find +the proposal-id by running "%s query gov proposals". -$ query gov tally 1 -`), +Example: +$ %s query gov tally 1 +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -384,7 +413,7 @@ $ query gov tally 1 // check to see if the proposal is in the store _, err = gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute) if err != nil { - return fmt.Errorf("Failed to fetch proposal-id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } // Construct query @@ -412,10 +441,15 @@ func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "params", Short: "Query the parameters of the governance process", - Long: strings.TrimSpace(`Query the all the parameters for the governance process: + Long: strings.TrimSpace( + fmt.Sprintf(`Query the all the parameters for the governance process. -$ query gov params -`), +Example: +$ %s query gov params +`, + version.ClientName, + ), + ), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -450,12 +484,17 @@ func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "param [param-type]", Args: cobra.ExactArgs(1), Short: "Query the parameters (voting|tallying|deposit) of the governance process", - Long: strings.TrimSpace(`Query the all the parameters for the governance process: + Long: strings.TrimSpace( + fmt.Sprintf(`Query the all the parameters for the governance process. -$ query gov param voting -$ query gov param tallying -$ query gov param deposit -`), +Example: +$ %s query gov param voting +$ %s query gov param tallying +$ %s query gov param deposit +`, + version.ClientName, version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -493,10 +532,15 @@ func GetCmdQueryProposer(queryRoute string, cdc *codec.Codec) *cobra.Command { Use: "proposer [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query the proposer of a governance proposal", - Long: strings.TrimSpace(`Query which address proposed a proposal with a given ID: + Long: strings.TrimSpace( + fmt.Sprintf(`Query which address proposed a proposal with a given ID. -$ query gov proposer 1 -`), +Example: +$ %s query gov proposer 1 +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index ad7108abb..de1b662ee 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/utils" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/gov" @@ -53,12 +54,14 @@ func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal", Short: "Submit a proposal along with an initial deposit", - Long: strings.TrimSpace(` -Submit a proposal along with an initial deposit. Proposal title, description, type and deposit can be given directly or through a proposal JSON file. For example: + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a proposal along with an initial deposit. +Proposal title, description, type and deposit can be given directly or through a proposal JSON file. -$ gov submit-proposal --proposal="path/to/proposal.json" --from mykey +Example: +$ %s tx gov submit-proposal --proposal="path/to/proposal.json" --from mykey -where proposal.json contains: +Where proposal.json contains: { "title": "Test Proposal", @@ -67,10 +70,13 @@ where proposal.json contains: "deposit": "10test" } -is equivalent to +Which is equivalent to: -$ gov submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --deposit="10test" --from mykey -`), +$ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --deposit="10test" --from mykey +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext(). @@ -113,12 +119,16 @@ func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { Use: "deposit [proposal-id] [deposit]", Args: cobra.ExactArgs(2), Short: "Deposit tokens for an active proposal", - Long: strings.TrimSpace(` -Submit a deposit for an active proposal. You can find the proposal-id by running " query gov proposals": + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a deposit for an active proposal. You can +find the proposal-id by running "%s query gov proposals". Example: -$ tx gov deposit 1 10stake --from mykey -`), +$ %s tx gov deposit 1 10stake --from mykey +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext(). @@ -157,12 +167,17 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { Use: "vote [proposal-id] [option]", Args: cobra.ExactArgs(2), Short: "Vote for an active proposal, options: yes/no/no_with_veto/abstain", - Long: strings.TrimSpace(` -Submit a vote for an active proposal. You can find the proposal-id by running " query gov proposals": + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a vote for an active proposal. You can +find the proposal-id by running "%s query gov proposals". + Example: -$ tx gov vote 1 yes --from mykey -`), +$ %s tx gov vote 1 yes --from mykey +`, + version.ClientName, version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext(). diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 7924fff45..a4fc82ad6 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "strings" "github.com/spf13/cobra" @@ -9,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/utils" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/params" @@ -22,9 +24,9 @@ func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { Use: "param-change [proposal-file]", Args: cobra.ExactArgs(1), Short: "Submit a parameter change proposal", - Long: strings.TrimSpace(` -Submit a parameter proposal along with an initial deposit. The proposal details -must be supplied via a JSON file. + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a parameter proposal along with an initial deposit. +The proposal details must be supplied via a JSON file. IMPORTANT: Currently parameter changes are evaluated but not validated, so it is very important that any "value" change is valid (ie. correct type and within bounds) @@ -35,8 +37,10 @@ Proper vetting of a parameter change proposal should prevent this from happening regardless. Example: -$ tx gov submit-proposal param-change --from= -where proposal.json contains: +$ %s tx gov submit-proposal param-change --from= + +Where proposal.json contains: + { "title": "Staking Param Change", "description": "Update max validators", @@ -54,7 +58,10 @@ where proposal.json contains: } ] } -`), +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext(). diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index 3b46ded5a..8aaa02519 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -18,10 +19,15 @@ func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "validator [validator-addr]", Short: "Query a validator", - Long: strings.TrimSpace(`Query details about an individual validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query details about an individual validator. -$ query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -51,10 +57,15 @@ func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command { Use: "validators", Short: "Query for all validators", Args: cobra.NoArgs, - Long: strings.TrimSpace(`Query details about all validators on a network: + Long: strings.TrimSpace( + fmt.Sprintf(`Query details about all validators on a network. -$ query staking validators -`), +Example: +$ %s query staking validators +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -78,10 +89,15 @@ func GetCmdQueryValidatorUnbondingDelegations(storeKey string, cdc *codec.Codec) return &cobra.Command{ Use: "unbonding-delegations-from [validator-addr]", Short: "Query all unbonding delegatations from a validator", - Long: strings.TrimSpace(`Query delegations that are unbonding _from_ a validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query delegations that are unbonding _from_ a validator. -$ query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -115,10 +131,15 @@ func GetCmdQueryValidatorRedelegations(storeKey string, cdc *codec.Codec) *cobra return &cobra.Command{ Use: "redelegations-from [validator-addr]", Short: "Query all outgoing redelegatations from a validator", - Long: strings.TrimSpace(`Query delegations that are redelegating _from_ a validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query delegations that are redelegating _from_ a validator. -$ query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -154,10 +175,15 @@ func GetCmdQueryDelegation(storeKey string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "delegation [delegator-addr] [validator-addr]", Short: "Query a delegation based on address and validator address", - Long: strings.TrimSpace(`Query delegations for an individual delegator on an individual validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query delegations for an individual delegator on an individual validator. -$ query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -199,10 +225,15 @@ func GetCmdQueryDelegations(storeKey string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "delegations [delegator-addr]", Short: "Query all delegations made by one delegator", - Long: strings.TrimSpace(`Query delegations for an individual delegator on all validators: + Long: strings.TrimSpace( + fmt.Sprintf(`Query delegations for an individual delegator on all validators. -$ query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p -`), +Example: +$ %s query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -239,10 +270,15 @@ func GetCmdQueryValidatorDelegations(storeKey string, cdc *codec.Codec) *cobra.C return &cobra.Command{ Use: "delegations-to [validator-addr]", Short: "Query all delegations made to one validator", - Long: strings.TrimSpace(`Query delegations on an individual validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query delegations on an individual validator. -$ query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -279,10 +315,15 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.C return &cobra.Command{ Use: "unbonding-delegation [delegator-addr] [validator-addr]", Short: "Query an unbonding-delegation record based on delegator and validator address", - Long: strings.TrimSpace(`Query unbonding delegations for an individual delegator on an individual validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query unbonding delegations for an individual delegator on an individual validator. -$ query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -314,10 +355,15 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra. return &cobra.Command{ Use: "unbonding-delegations [delegator-addr]", Short: "Query all unbonding-delegations records for one delegator", - Long: strings.TrimSpace(`Query unbonding delegations for an individual delegator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query unbonding delegations for an individual delegator. -$ query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p -`), +Example: +$ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -348,10 +394,15 @@ func GetCmdQueryRedelegation(storeKey string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "redelegation [delegator-addr] [src-validator-addr] [dst-validator-addr]", Short: "Query a redelegation record based on delegator and a source and destination validator address", - Long: strings.TrimSpace(`Query a redelegation record for an individual delegator between a source and destination validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query a redelegation record for an individual delegator between a source and destination validator. -$ query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj -`), +Example: +$ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj +`, + version.ClientName, + ), + ), Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -399,10 +450,15 @@ func GetCmdQueryRedelegations(storeKey string, cdc *codec.Codec) *cobra.Command Use: "redelegations [delegator-addr]", Args: cobra.ExactArgs(1), Short: "Query all redelegations records for one delegator", - Long: strings.TrimSpace(`Query all redelegation records for an individual delegator: + Long: strings.TrimSpace( + fmt.Sprintf(`Query all redelegation records for an individual delegator. -$ query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p -`), +Example: +$ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -438,10 +494,15 @@ func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command { Use: "pool", Args: cobra.NoArgs, Short: "Query the current staking pool values", - Long: strings.TrimSpace(`Query values for amounts stored in the staking pool: + Long: strings.TrimSpace( + fmt.Sprintf(`Query values for amounts stored in the staking pool. -$ query staking pool -`), +Example: +$ %s query staking pool +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -461,10 +522,15 @@ func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command { Use: "params", Args: cobra.NoArgs, Short: "Query the current staking parameters information", - Long: strings.TrimSpace(`Query values set as staking parameters: + Long: strings.TrimSpace( + fmt.Sprintf(`Query values set as staking parameters. -$ query staking params -`), +Example: +$ %s query staking params +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 6ad826b12..749a2c555 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/client" @@ -117,11 +118,16 @@ func GetCmdDelegate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "delegate [validator-addr] [amount]", Args: cobra.ExactArgs(2), - Short: "delegate liquid tokens to a validator", - Long: strings.TrimSpace(`Delegate an amount of liquid coins to a validator from your wallet: + Short: "Delegate liquid tokens to a validator", + Long: strings.TrimSpace( + fmt.Sprintf(`Delegate an amount of liquid coins to a validator from your wallet. -$ $ tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey -`), +Example: +$ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc)) cliCtx := context.NewCLIContext(). @@ -149,12 +155,17 @@ $ $ tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fp func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]", - Short: "redelegate illiquid tokens from one validator to another", + Short: "Redelegate illiquid tokens from one validator to another", Args: cobra.ExactArgs(3), - Long: strings.TrimSpace(`Redelegate an amount of illiquid staking tokens from one validator to another: + Long: strings.TrimSpace( + fmt.Sprintf(`Redelegate an amount of illiquid staking tokens from one validator to another. -$ $ tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 100stake --from mykey -`), +Example: +$ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 100stake --from mykey +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc)) cliCtx := context.NewCLIContext(). @@ -187,12 +198,17 @@ $ $ tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9l func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "unbond [validator-addr] [amount]", - Short: "unbond shares from a validator", + Short: "Unbond shares from a validator", Args: cobra.ExactArgs(2), - Long: strings.TrimSpace(`Unbond an amount of bonded shares from a validator: + Long: strings.TrimSpace( + fmt.Sprintf(`Unbond an amount of bonded shares from a validator. -$ $ tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey -`), +Example: +$ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey +`, + version.ClientName, + ), + ), RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc)) cliCtx := context.NewCLIContext().