diff --git a/client/flags/flags.go b/client/flags/flags.go index 4caf411dc2..956690f506 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -21,9 +21,7 @@ const ( // DefaultKeyringBackend DefaultKeyringBackend = keyring.BackendOS -) -const ( // BroadcastBlock defines a tx broadcasting mode where the client waits for // the tx to be committed in a block. BroadcastBlock = "block" @@ -50,6 +48,7 @@ const ( FlagSequence = "sequence" FlagMemo = "memo" FlagFees = "fees" + FlagGas = "gas" FlagGasPrices = "gas-prices" FlagBroadcastMode = "broadcast-mode" FlagDryRun = "dry-run" @@ -66,10 +65,7 @@ const ( // LineBreak can be included in a command list to provide a blank line // to help with readability -var ( - LineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}} - GasFlagVar = GasSetting{Gas: DefaultGasLimit} -) +var LineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}} // AddQueryFlagsToCmd adds common flags to a module query command. func AddQueryFlagsToCmd(cmd *cobra.Command) { @@ -112,16 +108,8 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { cmd.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature") - // --gas can accept integers and "simulate" - // - // TODO: Remove usage of var in favor of string as this is technical creating - // a singleton usage pattern and can cause issues in parallel tests. - // - // REF: https://github.com/cosmos/cosmos-sdk/issues/6545 - cmd.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf( - "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)", - GasFlagAuto, DefaultGasLimit, - )) + // --gas can accept integers and "auto" + cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", GasFlagAuto, DefaultGasLimit)) cmd.MarkFlagRequired(FlagChainID) @@ -135,62 +123,38 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { viper.BindPFlag(FlagKeyringBackend, cmd.Flags().Lookup(FlagKeyringBackend)) } -// GetCommands adds common flags to query commands. -// -// TODO: REMOVE. -func GetCommands(cmds ...*cobra.Command) []*cobra.Command { - for _, c := range cmds { - AddQueryFlagsToCmd(c) - } - - return cmds -} - -// PostCommands adds common flags for commands to post tx -// -// TODO: REMOVE. -func PostCommands(cmds ...*cobra.Command) []*cobra.Command { - for _, c := range cmds { - AddTxFlagsToCmd(c) - } - return cmds -} - // GasSetting encapsulates the possible values passed through the --gas flag. type GasSetting struct { Simulate bool Gas uint64 } -// Type returns the flag's value type. -func (v *GasSetting) Type() string { return "string" } - -// Set parses and sets the value of the --gas flag. -func (v *GasSetting) Set(s string) (err error) { - v.Simulate, v.Gas, err = ParseGas(s) - return -} - func (v *GasSetting) String() string { if v.Simulate { return GasFlagAuto } + return strconv.FormatUint(v.Gas, 10) } -// ParseGas parses the value of the gas option. -func ParseGas(gasStr string) (simulateAndExecute bool, gas uint64, err error) { +// ParseGasSetting parses a string gas value. The value may either be 'auto', +// which indicates a transaction should be executed in simulate mode to +// automatically find a sufficient gas value, or a string integer. It returns an +// error if a string integer is provided which cannot be parsed. +func ParseGasSetting(gasStr string) (GasSetting, error) { switch gasStr { case "": - gas = DefaultGasLimit + return GasSetting{false, DefaultGasLimit}, nil + case GasFlagAuto: - simulateAndExecute = true + return GasSetting{true, 0}, nil + default: - gas, err = strconv.ParseUint(gasStr, 10, 64) + gas, err := strconv.ParseUint(gasStr, 10, 64) if err != nil { - err = fmt.Errorf("gas must be either integer or %q", GasFlagAuto) - return + return GasSetting{}, fmt.Errorf("gas must be either integer or %s", GasFlagAuto) } + + return GasSetting{false, gas}, nil } - return } diff --git a/client/flags/flags_test.go b/client/flags/flags_test.go new file mode 100644 index 0000000000..5cc591bebb --- /dev/null +++ b/client/flags/flags_test.go @@ -0,0 +1,38 @@ +package flags_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/client/flags" +) + +func TestParseGasSetting(t *testing.T) { + testCases := []struct { + name string + input string + expected flags.GasSetting + expectErr bool + }{ + {"empty input", "", flags.GasSetting{false, flags.DefaultGasLimit}, false}, + {"auto", flags.GasFlagAuto, flags.GasSetting{true, 0}, false}, + {"valid custom gas", "73800", flags.GasSetting{false, 73800}, false}, + {"invalid custom gas", "-73800", flags.GasSetting{false, 0}, true}, + } + + for _, tc := range testCases { + tc := tc + + t.Run(tc.name, func(t *testing.T) { + gs, err := flags.ParseGasSetting(tc.input) + + if tc.expectErr { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tc.expected, gs) + } + }) + } +} diff --git a/client/tx/factory.go b/client/tx/factory.go index 767119f001..97884b5b47 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -52,13 +52,16 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory { gasAdj, _ := flagSet.GetFloat64(flags.FlagGasAdjustment) memo, _ := flagSet.GetString(flags.FlagMemo) + gasStr, _ := flagSet.GetString(flags.FlagGas) + gasSetting, _ := flags.ParseGasSetting(gasStr) + f := Factory{ txGenerator: clientCtx.TxGenerator, accountRetriever: clientCtx.AccountRetriever, keybase: clientCtx.Keyring, chainID: clientCtx.ChainID, - gas: flags.GasFlagVar.Gas, - simulateAndExecute: flags.GasFlagVar.Simulate, + gas: gasSetting.Gas, + simulateAndExecute: gasSetting.Simulate, accountNumber: accNum, sequence: accSeq, gasAdjustment: gasAdj, @@ -96,14 +99,16 @@ func NewFactoryFromDeprecated(input io.Reader) Factory { signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON } + gasSetting, _ := flags.ParseGasSetting(viper.GetString(flags.FlagGas)) + f := Factory{ keybase: kb, chainID: viper.GetString(flags.FlagChainID), accountNumber: viper.GetUint64(flags.FlagAccountNumber), sequence: viper.GetUint64(flags.FlagSequence), - gas: flags.GasFlagVar.Gas, + gas: gasSetting.Gas, + simulateAndExecute: gasSetting.Simulate, gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment), - simulateAndExecute: flags.GasFlagVar.Simulate, memo: viper.GetString(flags.FlagMemo), signMode: signMode, } diff --git a/client/tx/tx.go b/client/tx/tx.go index 2093ccea9e..cb64ac1b4b 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -149,7 +149,7 @@ func WriteGeneratedTxResponse( return } - simAndExec, gas, err := flags.ParseGas(br.Gas) + gasSetting, err := flags.ParseGasSetting(br.Gas) if rest.CheckBadRequestError(w, err) { return } @@ -157,14 +157,14 @@ func WriteGeneratedTxResponse( txf := Factory{fees: br.Fees, gasPrices: br.GasPrices}. WithAccountNumber(br.AccountNumber). WithSequence(br.Sequence). - WithGas(gas). + WithGas(gasSetting.Gas). WithGasAdjustment(gasAdj). WithMemo(br.Memo). WithChainID(br.ChainID). WithSimulateAndExecute(br.Simulate). WithTxGenerator(ctx.TxGenerator) - if br.Simulate || simAndExec { + if br.Simulate || gasSetting.Simulate { if gasAdj < 0 { rest.WriteErrorResponse(w, http.StatusBadRequest, sdkerrors.ErrorInvalidGasAdjustment.Error()) return diff --git a/simapp/simd/cmd/genaccounts.go b/simapp/simd/cmd/genaccounts.go index 8cfefc1865..d5b4ce67dc 100644 --- a/simapp/simd/cmd/genaccounts.go +++ b/simapp/simd/cmd/genaccounts.go @@ -161,6 +161,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") + flags.AddQueryFlagsToCmd(cmd) - return flags.GetCommands(cmd)[0] + return cmd } diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index 1d91d9e5b5..2168201783 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -50,5 +50,7 @@ $ tx broadcast ./mytxn.json }, } - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index bf69aee401..661108c80e 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -42,5 +42,7 @@ func GetDecodeCommand(clientCtx client.Context) *cobra.Command { } cmd.Flags().BoolP(flagHex, "x", false, "Treat input as hexadecimal instead of base64") - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index 3ca0b46b3a..0f425a9c00 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -49,5 +49,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea }, } - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/auth/client/cli/query.go b/x/auth/client/cli/query.go index bf9284d8df..939f2aed10 100644 --- a/x/auth/client/cli/query.go +++ b/x/auth/client/cli/query.go @@ -69,7 +69,9 @@ $ query auth params }, } - return flags.GetCommands(cmd)[0] + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetAccountCmd returns a query account that will display the state of the @@ -97,7 +99,9 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command { }, } - return flags.GetCommands(cmd)[0] + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // QueryTxsByEventsCmd returns a command to search through transactions by events. diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index f01d8592d9..48227e6caf 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -51,8 +51,9 @@ recommended to set such parameters manually. cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") + flags.AddTxFlagsToCmd(cmd) - return flags.PostCommands(cmd)[0] + return cmd } func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args []string) error { diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 8fa08062ac..f967a54343 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -48,14 +48,11 @@ account key. It implies --signature-only. Args: cobra.ExactArgs(1), } - cmd.Flags().String( - flagMultisig, "", - "Address of the multisig account on behalf of which the transaction shall be signed", - ) + cmd.Flags().String(flagMultisig, "", "Address of the multisig account on behalf of which the transaction shall be signed") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().Bool(flagSigOnly, true, "Print only the generated signature, then exit") - cmd = flags.PostCommands(cmd)[0] cmd.MarkFlagRequired(flags.FlagFrom) + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -178,19 +175,13 @@ be generated via the 'multisign' command. Args: cobra.ExactArgs(1), } - cmd.Flags().String( - flagMultisig, "", - "Address of the multisig account on behalf of which the transaction shall be signed", - ) - cmd.Flags().Bool( - flagAppend, true, - "Append the signature to the existing ones. If disabled, old signatures would be overwritten. Ignored if --multisig is on", - ) + cmd.Flags().String(flagMultisig, "", "Address of the multisig account on behalf of which the transaction shall be signed") + cmd.Flags().Bool(flagAppend, true, "Append the signature to the existing ones. If disabled, old signatures would be overwritten. Ignored if --multisig is on") cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") cmd.Flags().String(flags.FlagHome, "", "The application home directory") - cmd = flags.PostCommands(cmd)[0] cmd.MarkFlagRequired(flags.FlagFrom) + flags.AddTxFlagsToCmd(cmd) return cmd } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 84f90b6470..9be473676e 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -32,7 +32,9 @@ transaction will be not be performed as that will require RPC communication with Args: cobra.ExactArgs(1), } - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } func makeValidateSignaturesCmd(clientCtx client.Context) func(cmd *cobra.Command, args []string) error { diff --git a/x/auth/client/rest.go b/x/auth/client/rest.go index f825be42f1..1d52f0384b 100644 --- a/x/auth/client/rest.go +++ b/x/auth/client/rest.go @@ -19,17 +19,17 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, clientCtx client.Context, return } - simAndExec, gas, err := flags.ParseGas(br.Gas) + gasSetting, err := flags.ParseGasSetting(br.Gas) if rest.CheckBadRequestError(w, err) { return } txBldr := types.NewTxBuilder( - GetTxEncoder(clientCtx.Codec), br.AccountNumber, br.Sequence, gas, gasAdj, + GetTxEncoder(clientCtx.Codec), br.AccountNumber, br.Sequence, gasSetting.Gas, gasAdj, br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices, ) - if br.Simulate || simAndExec { + if br.Simulate || gasSetting.Simulate { if gasAdj < 0 { rest.WriteErrorResponse(w, http.StatusBadRequest, errors.ErrorInvalidGasAdjustment.Error()) return diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index 2cb5969b5b..8fe98c92de 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -65,13 +65,19 @@ func NewTxBuilderFromFlags(input io.Reader, fs *pflag.FlagSet, keyringPath strin fees, _ := fs.GetString(flags.FlagFees) gasPrices, _ := fs.GetString(flags.FlagGasPrices) + gasStr, _ := fs.GetString(flags.FlagGas) + gasSetting, err := flags.ParseGasSetting(gasStr) + if err != nil { + return TxBuilder{}, err + } + txbldr := TxBuilder{ keybase: kb, accountNumber: accNum, sequence: seq, - gas: flags.GasFlagVar.Gas, + gas: gasSetting.Gas, + simulateAndExecute: gasSetting.Simulate, gasAdjustment: gasAdjustment, - simulateAndExecute: flags.GasFlagVar.Simulate, chainID: chainID, memo: memo, } diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 81a0e6a225..d34e7f3c70 100644 --- a/x/bank/client/cli/query.go +++ b/x/bank/client/cli/query.go @@ -95,7 +95,9 @@ Example: } cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") - return flags.GetCommands(cmd)[0] + flags.AddQueryFlagsToCmd(cmd) + + return cmd } func GetCmdQueryTotalSupply() *cobra.Command { @@ -147,5 +149,7 @@ To query for the total supply of a specific coin denomination use: } cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") - return flags.GetCommands(cmd)[0] + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 8764794e05..6fb1cf537f 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -59,5 +59,7 @@ func NewSendTxCmd() *cobra.Command { }, } - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/crisis/client/cli/tx.go b/x/crisis/client/cli/tx.go index 29739d1f52..58a77eafdb 100644 --- a/x/crisis/client/cli/tx.go +++ b/x/crisis/client/cli/tx.go @@ -60,5 +60,7 @@ func NewMsgVerifyInvariantTxCmd() *cobra.Command { }, } - return flags.PostCommands(cmd)[0] + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/evidence/client/cli/query.go b/x/evidence/client/cli/query.go index 46cff2eb97..16473fa0a2 100644 --- a/x/evidence/client/cli/query.go +++ b/x/evidence/client/cli/query.go @@ -39,8 +39,9 @@ $ %s query %s --page=2 --limit=50 cmd.Flags().Int(flags.FlagPage, 1, "pagination page of evidence to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of evidence to query for") + flags.AddQueryFlagsToCmd(cmd) - return flags.GetCommands(cmd)[0] + return cmd } // QueryEvidenceCmd returns the command handler for evidence querying. Evidence diff --git a/x/evidence/client/cli/tx.go b/x/evidence/client/cli/tx.go index 3e03042c27..934f46056b 100644 --- a/x/evidence/client/cli/tx.go +++ b/x/evidence/client/cli/tx.go @@ -2,7 +2,6 @@ package cli import ( "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/spf13/cobra" @@ -24,7 +23,7 @@ func GetTxCmd(clientCtx client.Context, childCmds []*cobra.Command) *cobra.Comma submitEvidenceCmd := SubmitEvidenceCmd(clientCtx) for _, childCmd := range childCmds { - submitEvidenceCmd.AddCommand(flags.PostCommands(childCmd)[0]) + submitEvidenceCmd.AddCommand(childCmd) } // TODO: Add tx commands. diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 64d7114514..f7ae4992d7 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -193,8 +193,7 @@ $ %s gentx my-key-name --home=/path/to/home/dir --keyring-backend=os --chain-id= cmd.Flags().String(flags.FlagOutputDocument, "", "Write the genesis transaction JSON document to the given file instead of the default location") cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") cmd.Flags().AddFlagSet(fsCreateValidator) - - flags.PostCommands(cmd) + flags.AddTxFlagsToCmd(cmd) return cmd } diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 561a45d138..b3d9111748 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -27,7 +27,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { RunE: client.ValidateCmd, } - govQueryCmd.AddCommand(flags.GetCommands( + govQueryCmd.AddCommand( GetCmdQueryProposal(queryRoute, cdc), GetCmdQueryProposals(queryRoute, cdc), GetCmdQueryVote(queryRoute, cdc), @@ -37,14 +37,15 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { GetCmdQueryProposer(queryRoute, cdc), GetCmdQueryDeposit(queryRoute, cdc), GetCmdQueryDeposits(queryRoute, cdc), - GetCmdQueryTally(queryRoute, cdc))...) + GetCmdQueryTally(queryRoute, cdc), + ) return govQueryCmd } // GetCmdQueryProposal implements the query proposal command. func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "proposal [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query details of a single proposal", @@ -78,6 +79,10 @@ $ %s query gov proposal 1 return clientCtx.PrintOutput(proposal) // nolint:errcheck }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryProposals implements a query proposals command. @@ -165,6 +170,7 @@ $ %s query gov proposals --page=2 --limit=100 cmd.Flags().String(flagDepositor, "", "(optional) filter by proposals deposited on by depositor") cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted") cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status, status: deposit_period/voting_period/passed/rejected") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -172,7 +178,7 @@ $ %s query gov proposals --page=2 --limit=100 // Command to Get a Proposal Information // GetCmdQueryVote implements the query proposal vote command. func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "vote [proposal-id] [voter-addr]", Args: cobra.ExactArgs(2), Short: "Query details of a single vote", @@ -237,6 +243,10 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return clientCtx.PrintOutput(vote) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryVotes implements the command to query for proposal votes. @@ -298,15 +308,18 @@ $ %[1]s query gov votes 1 --page=2 --limit=100 return clientCtx.PrintOutput(votes) }, } + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of votes to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of votes to query for") + flags.AddQueryFlagsToCmd(cmd) + return cmd } // Command to Get a specific Deposit Information // GetCmdQueryDeposit implements the query proposal deposit command. func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "deposit [proposal-id] [depositer-addr]", Args: cobra.ExactArgs(2), Short: "Query details of a deposit", @@ -364,11 +377,15 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return clientCtx.PrintOutput(deposit) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryDeposits implements the command to query for proposal deposits. func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "deposits [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query deposits on a proposal", @@ -422,11 +439,15 @@ $ %s query gov deposits 1 return clientCtx.PrintOutput(dep) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryTally implements the command to query for proposal tally result. func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "tally [proposal-id]", Args: cobra.ExactArgs(1), Short: "Get the tally of a proposal vote", @@ -473,11 +494,15 @@ $ %s query gov tally 1 return clientCtx.PrintOutput(tally) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryProposal implements the query proposal command. func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "params", Short: "Query the parameters of the governance process", Long: strings.TrimSpace( @@ -515,11 +540,15 @@ $ %s query gov params return clientCtx.PrintOutput(types.NewParams(votingParams, tallyParams, depositParams)) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryProposal implements the query proposal command. func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "param [param-type]", Args: cobra.ExactArgs(1), Short: "Query the parameters (voting|tallying|deposit) of the governance process", @@ -563,11 +592,15 @@ $ %s query gov param deposit return clientCtx.PrintOutput(out) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryProposer implements the query proposer command. func GetCmdQueryProposer(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "proposer [proposal-id]", Args: cobra.ExactArgs(1), Short: "Query the proposer of a governance proposal", @@ -597,6 +630,8 @@ $ %s query gov proposer 1 return clientCtx.PrintOutput(prop) }, } -} -// DONTCOVER + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/ibc-transfer/client/cli/cli.go b/x/ibc-transfer/client/cli/cli.go index d36d99c861..e8850d9eff 100644 --- a/x/ibc-transfer/client/cli/cli.go +++ b/x/ibc-transfer/client/cli/cli.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" ) // NewTxCmd returns the transaction commands for IBC fungible token transfer @@ -17,9 +16,9 @@ func NewTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - txCmd.AddCommand(flags.PostCommands( + txCmd.AddCommand( NewTransferTxCmd(), - )...) + ) return txCmd } diff --git a/x/ibc-transfer/client/cli/tx.go b/x/ibc-transfer/client/cli/tx.go index dd0374504c..2088781167 100644 --- a/x/ibc-transfer/client/cli/tx.go +++ b/x/ibc-transfer/client/cli/tx.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" @@ -57,6 +58,7 @@ func NewTransferTxCmd() *cobra.Command { cmd.Flags().Uint64(flagTimeoutHeight, types.DefaultAbsolutePacketTimeoutHeight, "Absolute timeout block height. The timeout is disabled when set to 0.") cmd.Flags().Uint64(flagTimeoutTimestamp, types.DefaultAbsolutePacketTimeoutTimestamp, "Absolute timeout timestamp in nanoseconds. The timeout is disabled when set to 0.") + flags.AddTxFlagsToCmd(cmd) return cmd } diff --git a/x/ibc/02-client/client/cli/cli.go b/x/ibc/02-client/client/cli/cli.go index 8a93da818d..605996119c 100644 --- a/x/ibc/02-client/client/cli/cli.go +++ b/x/ibc/02-client/client/cli/cli.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ) @@ -18,12 +17,13 @@ func GetQueryCmd() *cobra.Command { RunE: client.ValidateCmd, } - queryCmd.AddCommand(flags.GetCommands( + queryCmd.AddCommand( GetCmdQueryClientStates(), GetCmdQueryClientState(), GetCmdQueryConsensusState(), GetCmdQueryHeader(), GetCmdNodeConsensusState(), - )...) + ) + return queryCmd } diff --git a/x/ibc/02-client/client/cli/query.go b/x/ibc/02-client/client/cli/query.go index 5b0c72df25..83ce8a4864 100644 --- a/x/ibc/02-client/client/cli/query.go +++ b/x/ibc/02-client/client/cli/query.go @@ -47,6 +47,7 @@ func GetCmdQueryClientStates() *cobra.Command { cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -85,6 +86,8 @@ func GetCmdQueryClientState() *cobra.Command { } cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + return cmd } @@ -127,12 +130,14 @@ func GetCmdQueryConsensusState() *cobra.Command { } cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + return cmd } // GetCmdQueryHeader defines the command to query the latest header on the chain func GetCmdQueryHeader() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "header", Short: "Query the latest header of the running chain", Long: "Query the latest Tendermint header of the running chain", @@ -153,12 +158,16 @@ func GetCmdQueryHeader() *cobra.Command { return clientCtx.PrintOutput(header) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdNodeConsensusState defines the command to query the latest consensus state of a node // The result is feed to client creation func GetCmdNodeConsensusState() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "node-state", Short: "Query a node consensus state", Long: "Query a node consensus state. This result is feed to the client creation transaction.", @@ -180,4 +189,8 @@ func GetCmdNodeConsensusState() *cobra.Command { return clientCtx.PrintOutput(state) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/ibc/03-connection/client/cli/cli.go b/x/ibc/03-connection/client/cli/cli.go index a7cb9a4213..84d1252e76 100644 --- a/x/ibc/03-connection/client/cli/cli.go +++ b/x/ibc/03-connection/client/cli/cli.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" ) @@ -17,11 +16,11 @@ func GetQueryCmd() *cobra.Command { SuggestionsMinimumDistance: 2, } - queryCmd.AddCommand(flags.GetCommands( + queryCmd.AddCommand( GetCmdQueryConnections(), GetCmdQueryConnection(), GetCmdQueryClientConnections(), - )...) + ) return queryCmd } @@ -36,12 +35,12 @@ func NewTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - txCmd.AddCommand(flags.PostCommands( + txCmd.AddCommand( NewConnectionOpenInitCmd(), NewConnectionOpenTryCmd(), NewConnectionOpenAckCmd(), NewConnectionOpenConfirmCmd(), - )...) + ) return txCmd } diff --git a/x/ibc/03-connection/client/cli/query.go b/x/ibc/03-connection/client/cli/query.go index 818bb56e4d..ed48a8aa6c 100644 --- a/x/ibc/03-connection/client/cli/query.go +++ b/x/ibc/03-connection/client/cli/query.go @@ -51,8 +51,10 @@ func GetCmdQueryConnections() *cobra.Command { return clientCtx.PrintOutput(res) }, } + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -84,7 +86,9 @@ func GetCmdQueryConnection() *cobra.Command { return clientCtx.PrintOutput(connRes) }, } + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -116,7 +120,9 @@ func GetCmdQueryClientConnections() *cobra.Command { return clientCtx.PrintOutput(connPathsRes) }, } + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) return cmd } diff --git a/x/ibc/03-connection/client/cli/tx.go b/x/ibc/03-connection/client/cli/tx.go index 7f406eea3d..64dc4db973 100644 --- a/x/ibc/03-connection/client/cli/tx.go +++ b/x/ibc/03-connection/client/cli/tx.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" @@ -56,6 +57,8 @@ func NewConnectionOpenInitCmd() *cobra.Command { }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } @@ -125,6 +128,8 @@ func NewConnectionOpenTryCmd() *cobra.Command { }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } @@ -180,6 +185,8 @@ func NewConnectionOpenAckCmd() *cobra.Command { }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } @@ -226,6 +233,8 @@ func NewConnectionOpenConfirmCmd() *cobra.Command { }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } diff --git a/x/ibc/04-channel/client/cli/cli.go b/x/ibc/04-channel/client/cli/cli.go index 986d5005b2..6a8c0f02e7 100644 --- a/x/ibc/04-channel/client/cli/cli.go +++ b/x/ibc/04-channel/client/cli/cli.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ) @@ -18,7 +17,7 @@ func GetQueryCmd() *cobra.Command { RunE: client.ValidateCmd, } - queryCmd.AddCommand(flags.GetCommands( + queryCmd.AddCommand( GetCmdQueryChannels(), GetCmdQueryChannel(), GetCmdQueryConnectionChannels(), @@ -28,7 +27,7 @@ func GetQueryCmd() *cobra.Command { GetCmdQueryUnrelayedPackets(), GetCmdQueryNextSequenceReceive(), // TODO: next sequence Send ? - )...) + ) return queryCmd } @@ -43,14 +42,14 @@ func NewTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - txCmd.AddCommand(flags.PostCommands( + txCmd.AddCommand( NewChannelOpenInitCmd(), NewChannelOpenTryCmd(), NewChannelOpenAckCmd(), NewChannelOpenConfirmCmd(), NewChannelCloseInitCmd(), NewChannelCloseConfirmCmd(), - )...) + ) return txCmd } diff --git a/x/ibc/04-channel/client/cli/query.go b/x/ibc/04-channel/client/cli/query.go index b6955bf7b6..e417e10af0 100644 --- a/x/ibc/04-channel/client/cli/query.go +++ b/x/ibc/04-channel/client/cli/query.go @@ -54,8 +54,10 @@ func GetCmdQueryChannels() *cobra.Command { return clientCtx.PrintOutput(res) }, } + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -90,7 +92,10 @@ func GetCmdQueryChannel() *cobra.Command { return clientCtx.PrintOutput(channelRes) }, } + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + return cmd } @@ -131,8 +136,10 @@ func GetCmdQueryConnectionChannels() *cobra.Command { return clientCtx.PrintOutput(res) }, } + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -164,6 +171,9 @@ func GetCmdQueryChannelClientState() *cobra.Command { return clientCtx.PrintOutput(clientStateRes) }, } + + flags.AddQueryFlagsToCmd(cmd) + return cmd } @@ -205,8 +215,10 @@ func GetCmdQueryPacketCommitments() *cobra.Command { return clientCtx.PrintOutput(res) }, } + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -246,7 +258,10 @@ func GetCmdQueryPacketCommitment() *cobra.Command { return clientCtx.PrintOutput(res) }, } + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) + return cmd } @@ -302,9 +317,11 @@ An unrelayed packet corresponds to: return clientCtx.PrintOutput(res) }, } + cmd.Flags().Int64Slice(flagSequences, []int64{}, "comma separated list of packet sequence numbers") cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -339,7 +356,9 @@ func GetCmdQueryNextSequenceReceive() *cobra.Command { return clientCtx.PrintOutput(sequenceRes) }, } + cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results") + flags.AddQueryFlagsToCmd(cmd) return cmd } diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index c2c9433614..7674343fe2 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/pflag" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" @@ -51,8 +52,10 @@ func NewChannelOpenInitCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels") cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version") + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -102,8 +105,10 @@ func NewChannelOpenTryCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels") cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version") + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -147,14 +152,16 @@ func NewChannelOpenAckCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version") + flags.AddTxFlagsToCmd(cmd) return cmd } // NewChannelOpenConfirmCmd returns the command to create a MsgChannelOpenConfirm transaction func NewChannelOpenConfirmCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "open-confirm [port-id] [channel-id] [/path/to/proof_ack.json] [proof-height]", Short: "Creates and sends a ChannelOpenConfirm message", Args: cobra.ExactArgs(4), @@ -188,11 +195,15 @@ func NewChannelOpenConfirmCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + + return cmd } // NewChannelCloseInitCmd returns the command to create a MsgChannelCloseInit transaction func NewChannelCloseInitCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "close-init [port-id] [channel-id]", Short: "Creates and sends a ChannelCloseInit message", Args: cobra.ExactArgs(2), @@ -214,11 +225,15 @@ func NewChannelCloseInitCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + + return cmd } // NewChannelCloseConfirmCmd returns the command to create a MsgChannelCloseConfirm transaction func NewChannelCloseConfirmCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "close-confirm [port-id] [channel-id] [/path/to/proof_init.json] [proof-height]", Short: "Creates and sends a ChannelCloseConfirm message", Args: cobra.ExactArgs(4), @@ -252,6 +267,10 @@ func NewChannelCloseConfirmCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + + return cmd } func channelOrder(fs *pflag.FlagSet) types.Order { diff --git a/x/ibc/07-tendermint/client/cli/cli.go b/x/ibc/07-tendermint/client/cli/cli.go index 1dde6e2e41..7a762efa0b 100644 --- a/x/ibc/07-tendermint/client/cli/cli.go +++ b/x/ibc/07-tendermint/client/cli/cli.go @@ -3,7 +3,6 @@ package cli import ( "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" ) @@ -16,11 +15,11 @@ func NewTxCmd() *cobra.Command { SuggestionsMinimumDistance: 2, } - txCmd.AddCommand(flags.PostCommands( + txCmd.AddCommand( NewCreateClientCmd(), NewUpdateClientCmd(), NewSubmitMisbehaviourCmd(), - )...) + ) return txCmd } diff --git a/x/ibc/07-tendermint/client/cli/tx.go b/x/ibc/07-tendermint/client/cli/tx.go index f11d3826b2..7395aad26e 100644 --- a/x/ibc/07-tendermint/client/cli/tx.go +++ b/x/ibc/07-tendermint/client/cli/tx.go @@ -16,6 +16,7 @@ import ( lite "github.com/tendermint/tendermint/lite2" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/version" evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" @@ -119,6 +120,7 @@ func NewCreateClientCmd() *cobra.Command { cmd.Flags().String(flagTrustLevel, "default", "light client trust level fraction for header updates") cmd.Flags().String(flagProofSpecs, "default", "proof specs format to be used for verification") + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -126,7 +128,7 @@ func NewCreateClientCmd() *cobra.Command { // NewUpdateClientCmd defines the command to update a client as defined in // https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#update func NewUpdateClientCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "update [client-id] [path/to/header.json]", Short: "update existing client with a header", Long: "update existing tendermint client with a tendermint header", @@ -164,13 +166,17 @@ func NewUpdateClientCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + + return cmd } // NewSubmitMisbehaviourCmd defines the command to submit a misbehaviour to invalidate // previous state roots and prevent future updates as defined in // https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#misbehaviour func NewSubmitMisbehaviourCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "misbehaviour [path/to/evidence.json]", Short: "submit a client misbehaviour", Long: "submit a client misbehaviour to invalidate to invalidate previous state roots and prevent future updates", @@ -206,6 +212,10 @@ func NewSubmitMisbehaviourCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + + return cmd } func parseFraction(fraction string) (tmmath.Fraction, error) { diff --git a/x/ibc/09-localhost/client/cli/cli.go b/x/ibc/09-localhost/client/cli/cli.go index 3d21f77583..5ab6d0f23b 100644 --- a/x/ibc/09-localhost/client/cli/cli.go +++ b/x/ibc/09-localhost/client/cli/cli.go @@ -3,7 +3,6 @@ package cli import ( "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" ) @@ -16,9 +15,9 @@ func NewTxCmd() *cobra.Command { SuggestionsMinimumDistance: 2, } - txCmd.AddCommand(flags.PostCommands( + txCmd.AddCommand( NewCreateClientCmd(), - )...) + ) return txCmd } diff --git a/x/ibc/09-localhost/client/cli/tx.go b/x/ibc/09-localhost/client/cli/tx.go index 969bd51dc0..0e29c67c19 100644 --- a/x/ibc/09-localhost/client/cli/tx.go +++ b/x/ibc/09-localhost/client/cli/tx.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" @@ -36,5 +37,8 @@ func NewCreateClientCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + + flags.AddTxFlagsToCmd(cmd) + return cmd } diff --git a/x/ibc/client/cli/cli.go b/x/ibc/client/cli/cli.go index 1f94b7f486..0f35ea0da4 100644 --- a/x/ibc/client/cli/cli.go +++ b/x/ibc/client/cli/cli.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client" connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" @@ -23,12 +22,13 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - ibcTxCmd.AddCommand(flags.PostCommands( + ibcTxCmd.AddCommand( tendermint.GetTxCmd(), localhost.GetTxCmd(), connection.GetTxCmd(), channel.GetTxCmd(), - )...) + ) + return ibcTxCmd } @@ -43,10 +43,11 @@ func GetQueryCmd() *cobra.Command { RunE: client.ValidateCmd, } - ibcQueryCmd.AddCommand(flags.GetCommands( + ibcQueryCmd.AddCommand( ibcclient.GetQueryCmd(), connection.GetQueryCmd(), channel.GetQueryCmd(), - )...) + ) + return ibcQueryCmd } diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index 0aa91a1a4d..6fba11aecf 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -23,11 +23,9 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command { } mintingQueryCmd.AddCommand( - flags.GetCommands( - GetCmdQueryParams(cdc), - GetCmdQueryInflation(cdc), - GetCmdQueryAnnualProvisions(cdc), - )..., + GetCmdQueryParams(cdc), + GetCmdQueryInflation(cdc), + GetCmdQueryAnnualProvisions(cdc), ) return mintingQueryCmd @@ -36,7 +34,7 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command { // GetCmdQueryParams implements a command to return the current minting // parameters. func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "params", Short: "Query the current minting parameters", Args: cobra.NoArgs, @@ -57,12 +55,16 @@ func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { return clientCtx.PrintOutput(params) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryInflation implements a command to return the current minting // inflation value. func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "inflation", Short: "Query the current minting inflation value", Args: cobra.NoArgs, @@ -83,12 +85,16 @@ func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { return clientCtx.PrintOutput(inflation) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryAnnualProvisions implements a command to return the current minting // annual provisions value. func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "annual-provisions", Short: "Query the current minting annual provisions value", Args: cobra.NoArgs, @@ -109,4 +115,8 @@ func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { return clientCtx.PrintOutput(inflation) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index ce5bc77afd..1d4725b86e 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -58,5 +58,7 @@ func NewQuerySubspaceParamsCmd(m codec.JSONMarshaler) *cobra.Command { }, } - return flags.GetCommands(cmd)[0] + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 63f90788b1..4952ed37ef 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -26,10 +26,8 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { } slashingQueryCmd.AddCommand( - flags.GetCommands( - GetCmdQuerySigningInfo(queryRoute, cdc), - GetCmdQueryParams(cdc), - )..., + GetCmdQuerySigningInfo(queryRoute, cdc), + GetCmdQueryParams(cdc), ) return slashingQueryCmd @@ -38,7 +36,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQuerySigningInfo implements the command to query signing info. func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "signing-info [validator-conspub]", Short: "Query a validator's signing information", Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator: @@ -75,11 +73,15 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge return clientCtx.PrintOutput(signingInfo) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryParams implements a command to fetch slashing parameters. func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "params", Short: "Query the current slashing parameters", Args: cobra.NoArgs, @@ -101,4 +103,8 @@ $ query slashing params return clientCtx.PrintOutput(params) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index f09f858b2d..bc992b3049 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -45,5 +45,8 @@ $ tx slashing unjail --from mykey return tx.GenerateOrBroadcastTx(clientCtx, msg) }, } - return flags.PostCommands(cmd)[0] + + flags.AddTxFlagsToCmd(cmd) + + return cmd } diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index 451dbc0c02..9608bda977 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -24,7 +24,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } - stakingQueryCmd.AddCommand(flags.GetCommands( + stakingQueryCmd.AddCommand( GetCmdQueryDelegation(queryRoute, cdc), GetCmdQueryDelegations(queryRoute, cdc), GetCmdQueryUnbondingDelegation(queryRoute, cdc), @@ -38,14 +38,15 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { GetCmdQueryValidatorRedelegations(queryRoute, cdc), GetCmdQueryHistoricalInfo(queryRoute, cdc), GetCmdQueryParams(queryRoute, cdc), - GetCmdQueryPool(queryRoute, cdc))...) + GetCmdQueryPool(queryRoute, cdc), + ) return stakingQueryCmd } // GetCmdQueryValidator implements the validator query command. func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "validator [validator-addr]", Short: "Query a validator", Long: strings.TrimSpace( @@ -83,11 +84,15 @@ $ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhff return clientCtx.PrintOutput(validator) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryValidators implements the query all validators command. func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "validators", Short: "Query for all validators", Args: cobra.NoArgs, @@ -121,6 +126,10 @@ $ %s query staking validators return clientCtx.PrintOutput(validators) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command. @@ -167,6 +176,7 @@ $ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj6 cmd.Flags().Int(flags.FlagPage, 1, "pagination page of unbonding delegations to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of unbonding delegations to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -174,7 +184,7 @@ $ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj6 // GetCmdQueryValidatorRedelegations implements the query all redelegatations // from a validator command. func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "redelegations-from [validator-addr]", Short: "Query all outgoing redelegatations from a validator", Long: strings.TrimSpace( @@ -214,11 +224,15 @@ $ %s query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryDelegation the query delegation command. func GetCmdQueryDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "delegation [delegator-addr] [validator-addr]", Short: "Query a delegation based on address and validator address", Long: strings.TrimSpace( @@ -263,12 +277,16 @@ $ %s query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosm return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryDelegations implements the command to query all the delegations // made from one delegator. func GetCmdQueryDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "delegations [delegator-addr]", Short: "Query all delegations made by one delegator", Long: strings.TrimSpace( @@ -308,6 +326,10 @@ $ %s query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryValidatorDelegations implements the command to query all the @@ -358,6 +380,7 @@ $ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ld cmd.Flags().Int(flags.FlagPage, 1, "pagination page of delegations to query for") cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of delegations to query for") + flags.AddQueryFlagsToCmd(cmd) return cmd } @@ -365,7 +388,7 @@ $ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ld // GetCmdQueryUnbondingDelegation implements the command to query a single // unbonding-delegation record. func GetCmdQueryUnbondingDelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "unbonding-delegation [delegator-addr] [validator-addr]", Short: "Query an unbonding-delegation record based on delegator and validator address", Long: strings.TrimSpace( @@ -410,12 +433,16 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7 return clientCtx.PrintOutput(ubd) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryUnbondingDelegations implements the command to query all the // unbonding-delegation records for a delegator. func GetCmdQueryUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "unbonding-delegations [delegator-addr]", Short: "Query all unbonding-delegations records for one delegator", Long: strings.TrimSpace( @@ -455,12 +482,16 @@ $ %s query staking unbonding-delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld return clientCtx.PrintOutput(ubds) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryRedelegation implements the command to query a single // redelegation record. func GetCmdQueryRedelegation(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &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( @@ -510,12 +541,16 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryRedelegations implements the command to query all the // redelegation records for a delegator. func GetCmdQueryRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "redelegations [delegator-addr]", Args: cobra.ExactArgs(1), Short: "Query all redelegations records for one delegator", @@ -555,11 +590,15 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryHistoricalInfo implements the historical info query command func GetCmdQueryHistoricalInfo(queryRoute string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "historical-info [height]", Args: cobra.ExactArgs(1), Short: "Query historical info at given height", @@ -599,11 +638,15 @@ $ %s query staking historical-info 5 return clientCtx.PrintOutput(resp) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryPool implements the pool query command. func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "pool", Args: cobra.NoArgs, Short: "Query the current staking pool values", @@ -632,11 +675,15 @@ $ %s query staking pool return clientCtx.PrintOutput(pool) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetCmdQueryParams implements the params query command. func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "params", Args: cobra.NoArgs, Short: "Query the current staking parameters information", @@ -663,4 +710,8 @@ $ %s query staking params return clientCtx.PrintOutput(params) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 65ca79f23f..bdad214cbc 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -37,13 +37,13 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command { RunE: client.ValidateCmd, } - stakingTxCmd.AddCommand(flags.PostCommands( + stakingTxCmd.AddCommand( NewCreateValidatorCmd(clientCtx), NewEditValidatorCmd(clientCtx), NewDelegateCmd(clientCtx), NewRedelegateCmd(clientCtx), NewUnbondCmd(clientCtx), - )...) + ) return stakingTxCmd } @@ -64,6 +64,7 @@ func NewCreateValidatorCmd(clientCtx client.Context) *cobra.Command { return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } + cmd.Flags().AddFlagSet(FlagSetPublicKey()) cmd.Flags().AddFlagSet(FlagSetAmount()) cmd.Flags().AddFlagSet(flagSetDescriptionCreate()) @@ -72,6 +73,7 @@ func NewCreateValidatorCmd(clientCtx client.Context) *cobra.Command { cmd.Flags().String(FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", flags.FlagGenerateOnly)) cmd.Flags().String(FlagNodeID, "", "The node's ID") + flags.AddTxFlagsToCmd(cmd) _ = cmd.MarkFlagRequired(flags.FlagFrom) _ = cmd.MarkFlagRequired(FlagAmount) @@ -140,6 +142,7 @@ func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command { cmd.Flags().AddFlagSet(flagSetDescriptionEdit()) cmd.Flags().AddFlagSet(flagSetCommissionUpdate()) cmd.Flags().AddFlagSet(FlagSetMinSelfDelegation()) + flags.AddTxFlagsToCmd(cmd) return cmd } @@ -181,6 +184,8 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } @@ -226,6 +231,8 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } @@ -266,6 +273,8 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s }, } + flags.AddTxFlagsToCmd(cmd) + return cmd } diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index 21783826f1..de45e805f7 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -17,17 +17,18 @@ func GetQueryCmd() *cobra.Command { Use: types.ModuleName, Short: "Querying commands for the upgrade module", } - cmd.AddCommand(flags.GetCommands( + + cmd.AddCommand( GetCurrentPlanCmd(), GetAppliedPlanCmd(), - )...) + ) return cmd } // GetCurrentPlanCmd returns the query upgrade plan command func GetCurrentPlanCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "plan", Short: "get upgrade plan (if one exists)", Long: "Gets the currently scheduled upgrade plan, if one exists", @@ -52,12 +53,16 @@ func GetCurrentPlanCmd() *cobra.Command { return clientCtx.PrintOutput(res.Plan) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } // GetAppliedPlanCmd returns information about the block at which a completed // upgrade was applied func GetAppliedPlanCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "applied [upgrade-name]", Short: "block header for height at which a completed upgrade was applied", Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied.\n" + @@ -99,4 +104,8 @@ func GetAppliedPlanCmd() *cobra.Command { return clientCtx.PrintOutput(string(bz)) }, } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd } diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index c509fd03ed..2e516a815c 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -30,7 +30,6 @@ func GetTxCmd() *cobra.Command { Use: types.ModuleName, Short: "Upgrade transaction subcommands", } - cmd.AddCommand(flags.PostCommands()...) return cmd } @@ -140,6 +139,7 @@ func NewCmdSubmitCancelUpgradeProposal(clientCtx client.Context) *cobra.Command cmd.Flags().String(cli.FlagTitle, "", "title of proposal") cmd.Flags().String(cli.FlagDescription, "", "description of proposal") cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") + flags.AddTxFlagsToCmd(cmd) return cmd }