From 6a6d6c9fc4139ecfd9a5a1a33e3c397bf0ac2828 Mon Sep 17 00:00:00 2001 From: Alexander Peters Date: Mon, 14 Jun 2021 09:57:59 +0200 Subject: [PATCH] Add cli alias (#536) * Add cli alias * Review feedback --- x/wasm/client/cli/new_tx.go | 21 +++++++++-------- x/wasm/client/cli/query.go | 46 +++++++++++++++++++++---------------- x/wasm/client/cli/tx.go | 21 +++++++++-------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index b88cb44b471..cc0ff4ad4f1 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -14,9 +14,10 @@ import ( // MigrateContractCmd will migrate a contract to a new code version func MigrateContractCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "migrate [contract_addr_bech32] [new_code_id_int64] [json_encoded_migration_args]", - Short: "Migrate a wasm contract to a new code version", - Args: cobra.ExactArgs(3), + Use: "migrate [contract_addr_bech32] [new_code_id_int64] [json_encoded_migration_args]", + Short: "Migrate a wasm contract to a new code version", + Aliases: []string{"update", "mig", "m"}, + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -55,9 +56,10 @@ func parseMigrateContractArgs(args []string, cliCtx client.Context) (types.MsgMi // UpdateContractAdminCmd sets an new admin for a contract func UpdateContractAdminCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "set-contract-admin [contract_addr_bech32] [new_admin_addr_bech32]", - Short: "Set new admin for a contract", - Args: cobra.ExactArgs(2), + Use: "set-contract-admin [contract_addr_bech32] [new_admin_addr_bech32]", + Short: "Set new admin for a contract", + Aliases: []string{"new-admin", "admin", "set-adm", "sa"}, + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -87,9 +89,10 @@ func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) (types.M // ClearContractAdminCmd clears an admin for a contract func ClearContractAdminCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "clear-contract-admin [contract_addr_bech32]", - Short: "Clears admin for a contract to prevent further migrations", - Args: cobra.ExactArgs(1), + Use: "clear-contract-admin [contract_addr_bech32]", + Short: "Clears admin for a contract to prevent further migrations", + Aliases: []string{"clear-admin", "clr-adm"}, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { diff --git a/x/wasm/client/cli/query.go b/x/wasm/client/cli/query.go index 32409554f65..96dd130ad12 100644 --- a/x/wasm/client/cli/query.go +++ b/x/wasm/client/cli/query.go @@ -40,10 +40,11 @@ func GetQueryCmd() *cobra.Command { // GetCmdListCode lists all wasm code uploaded func GetCmdListCode() *cobra.Command { cmd := &cobra.Command{ - Use: "list-code", - Short: "List all wasm bytecode on the chain", - Long: "List all wasm bytecode on the chain", - Args: cobra.ExactArgs(0), + Use: "list-code", + Short: "List all wasm bytecode on the chain", + Long: "List all wasm bytecode on the chain", + Aliases: []string{"list-codes", "codes", "lco"}, + Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -75,10 +76,11 @@ func GetCmdListCode() *cobra.Command { // GetCmdListContractByCode lists all wasm code uploaded for given code id func GetCmdListContractByCode() *cobra.Command { cmd := &cobra.Command{ - Use: "list-contract-by-code [code_id]", - Short: "List wasm all bytecode on the chain for given code id", - Long: "List wasm all bytecode on the chain for given code id", - Args: cobra.ExactArgs(1), + Use: "list-contract-by-code [code_id]", + Short: "List wasm all bytecode on the chain for given code id", + Long: "List wasm all bytecode on the chain for given code id", + Aliases: []string{"list-contracts-by-code", "list-contracts", "contracts", "lca"}, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -116,10 +118,11 @@ func GetCmdListContractByCode() *cobra.Command { // GetCmdQueryCode returns the bytecode for a given contract func GetCmdQueryCode() *cobra.Command { cmd := &cobra.Command{ - Use: "code [code_id] [output filename]", - Short: "Downloads wasm bytecode for given code id", - Long: "Downloads wasm bytecode for given code id", - Args: cobra.ExactArgs(2), + Use: "code [code_id] [output filename]", + Short: "Downloads wasm bytecode for given code id", + Long: "Downloads wasm bytecode for given code id", + Aliases: []string{"source-code", "source"}, + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -156,10 +159,11 @@ func GetCmdQueryCode() *cobra.Command { // GetCmdGetContractInfo gets details about a given contract func GetCmdGetContractInfo() *cobra.Command { cmd := &cobra.Command{ - Use: "contract [bech32_address]", - Short: "Prints out metadata of a contract given its address", - Long: "Prints out metadata of a contract given its address", - Args: cobra.ExactArgs(1), + Use: "contract [bech32_address]", + Short: "Prints out metadata of a contract given its address", + Long: "Prints out metadata of a contract given its address", + Aliases: []string{"meta", "c"}, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -193,6 +197,7 @@ func GetCmdGetContractState() *cobra.Command { cmd := &cobra.Command{ Use: "contract-state", Short: "Querying commands for the wasm module", + Aliases: []string{"state", "cs", "s"}, DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -338,10 +343,11 @@ func GetCmdGetContractStateSmart() *cobra.Command { // GetCmdGetContractHistory prints the code history for a given contract func GetCmdGetContractHistory() *cobra.Command { cmd := &cobra.Command{ - Use: "contract-history [bech32_address]", - Short: "Prints out the code history for a contract given its address", - Long: "Prints out the code history for a contract given its address", - Args: cobra.ExactArgs(1), + Use: "contract-history [bech32_address]", + Short: "Prints out the code history for a contract given its address", + Long: "Prints out the code history for a contract given its address", + Aliases: []string{"history", "hist", "ch"}, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { diff --git a/x/wasm/client/cli/tx.go b/x/wasm/client/cli/tx.go index a400fe9bc89..3bf05e70b51 100644 --- a/x/wasm/client/cli/tx.go +++ b/x/wasm/client/cli/tx.go @@ -52,9 +52,10 @@ func GetTxCmd() *cobra.Command { // StoreCodeCmd will upload code to be reused. func StoreCodeCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "store [wasm file] --source [source] --builder [builder]", - Short: "Upload a wasm binary", - Args: cobra.ExactArgs(1), + Use: "store [wasm file] --source [source] --builder [builder]", + Short: "Upload a wasm binary", + Aliases: []string{"upload", "st", "s"}, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) msg, err := parseStoreCodeArgs(args[0], clientCtx.GetFromAddress(), cmd.Flags()) @@ -144,9 +145,10 @@ func parseStoreCodeArgs(file string, sender sdk.AccAddress, flags *flag.FlagSet) // InstantiateContractCmd will instantiate a contract from previously uploaded code. func InstantiateContractCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "instantiate [code_id_int64] [json_encoded_init_args] --label [text] --admin [address,optional] --amount [coins,optional]", - Short: "Instantiate a wasm contract", - Args: cobra.ExactArgs(2), + Use: "instantiate [code_id_int64] [json_encoded_init_args] --label [text] --admin [address,optional] --amount [coins,optional]", + Short: "Instantiate a wasm contract", + Aliases: []string{"start", "init", "inst", "i"}, + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -211,9 +213,10 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag // ExecuteContractCmd will instantiate a contract from previously uploaded code. func ExecuteContractCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "execute [contract_addr_bech32] [json_encoded_send_args] --amount [coins,optional]", - Short: "Execute a command on a wasm contract", - Args: cobra.ExactArgs(2), + Use: "execute [contract_addr_bech32] [json_encoded_send_args] --amount [coins,optional]", + Short: "Execute a command on a wasm contract", + Aliases: []string{"run", "call", "exec", "ex", "e"}, + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd)