Skip to content

Commit

Permalink
Add cli alias (cosmos#536)
Browse files Browse the repository at this point in the history
* Add cli alias

* Review feedback
  • Loading branch information
alpe authored Jun 14, 2021
1 parent 1ada14e commit 6a6d6c9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
21 changes: 12 additions & 9 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 26 additions & 20 deletions x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 12 additions & 9 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6a6d6c9

Please sign in to comment.