Skip to content

Commit

Permalink
Add SilenceUsage flag to hide menu when an error occurs. (CosmWasm#1068)
Browse files Browse the repository at this point in the history
* Add SilenceUsage flag to hide menu when an error occurs.

* Fix lint errors
  • Loading branch information
pinosu authored and NoahSaso committed Dec 2, 2022
1 parent 81b61aa commit 5e735f2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func GenesisStoreCodeCmd(defaultNodeHome string, genesisMutator GenesisMutator)
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagRunAs, "", "The address that is stored as code creator")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
Expand Down Expand Up @@ -136,6 +137,7 @@ func GenesisInstantiateContractCmd(defaultNodeHome string, genesisMutator Genesi
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
Expand Down Expand Up @@ -189,6 +191,7 @@ func GenesisExecuteContractCmd(defaultNodeHome string, genesisMutator GenesisMut
return nil
})
},
SilenceUsage: true,
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract along with command")
cmd.Flags().String(flagRunAs, "", "The address that pays the funds.")
Expand Down Expand Up @@ -217,6 +220,7 @@ func GenesisListCodesCmd(defaultNodeHome string, genReader GenesisReader) *cobra
}
return printJSONOutput(cmd, all)
},
SilenceUsage: true,
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
flags.AddQueryFlagsToCmd(cmd)
Expand All @@ -239,6 +243,7 @@ func GenesisListContractsCmd(defaultNodeHome string, genReader GenesisReader) *c
all := GetAllContracts(state)
return printJSONOutput(cmd, all)
},
SilenceUsage: true,
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
flags.AddQueryFlagsToCmd(cmd)
Expand Down
10 changes: 10 additions & 0 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func ProposalStoreCodeCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagRunAs, "", "The address that is stored as code creator")
Expand Down Expand Up @@ -157,6 +158,7 @@ func ProposalInstantiateContractCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
Expand Down Expand Up @@ -222,6 +224,7 @@ func ProposalMigrateContractCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}

// proposal flags
Expand Down Expand Up @@ -296,6 +299,7 @@ func ProposalExecuteContractCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
cmd.Flags().String(flagRunAs, "", "The address that is passed as sender to the contract on proposal execution")
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
Expand Down Expand Up @@ -355,6 +359,7 @@ func ProposalSudoContractCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}

// proposal flagsExecute
Expand Down Expand Up @@ -414,6 +419,7 @@ func ProposalUpdateContractAdminCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down Expand Up @@ -466,6 +472,7 @@ func ProposalClearContractAdminCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down Expand Up @@ -522,6 +529,7 @@ func ProposalPinCodesCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down Expand Up @@ -590,6 +598,7 @@ func ProposalUnpinCodesCmd() *cobra.Command {

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down Expand Up @@ -705,6 +714,7 @@ $ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}
// proposal flags
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down
3 changes: 3 additions & 0 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func MigrateContractCmd() *cobra.Command {
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}
flags.AddTxFlagsToCmd(cmd)
return cmd
Expand Down Expand Up @@ -79,6 +80,7 @@ func UpdateContractAdminCmd() *cobra.Command {
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}
flags.AddTxFlagsToCmd(cmd)
return cmd
Expand Down Expand Up @@ -115,6 +117,7 @@ func ClearContractAdminCmd() *cobra.Command {
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}
flags.AddTxFlagsToCmd(cmd)
return cmd
Expand Down
18 changes: 16 additions & 2 deletions x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GetQueryCmd() *cobra.Command {
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
SilenceUsage: true,
}
queryCmd.AddCommand(
GetCmdListCode(),
Expand Down Expand Up @@ -137,6 +138,7 @@ func GetCmdListCode() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "list codes")
Expand Down Expand Up @@ -182,6 +184,7 @@ func GetCmdListContractByCode() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "list contracts by code")
Expand Down Expand Up @@ -224,6 +227,7 @@ func GetCmdQueryCode() *cobra.Command {
fmt.Printf("Downloading wasm code to %s\n", args[1])
return os.WriteFile(args[1], res.Data, 0o600)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
Expand Down Expand Up @@ -263,6 +267,7 @@ func GetCmdQueryCodeInfo() *cobra.Command {

return clientCtx.PrintProto(res.CodeInfoResponse)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
Expand Down Expand Up @@ -298,6 +303,7 @@ func GetCmdGetContractInfo() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
Expand All @@ -312,6 +318,7 @@ func GetCmdGetContractState() *cobra.Command {
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
SilenceUsage: true,
}
cmd.AddCommand(
GetCmdGetContractStateAll(),
Expand Down Expand Up @@ -355,6 +362,7 @@ func GetCmdGetContractStateAll() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "contract state")
Expand Down Expand Up @@ -396,6 +404,7 @@ func GetCmdGetContractStateRaw() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
decoder.RegisterFlags(cmd.PersistentFlags(), "key argument")
flags.AddQueryFlagsToCmd(cmd)
Expand Down Expand Up @@ -444,6 +453,7 @@ func GetCmdGetContractStateSmart() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
decoder.RegisterFlags(cmd.PersistentFlags(), "query argument")
flags.AddQueryFlagsToCmd(cmd)
Expand Down Expand Up @@ -487,6 +497,7 @@ func GetCmdGetContractHistory() *cobra.Command {

return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}

flags.AddQueryFlagsToCmd(cmd)
Expand All @@ -499,7 +510,7 @@ func GetCmdListPinnedCode() *cobra.Command {
cmd := &cobra.Command{
Use: "pinned",
Short: "List all pinned code ids",
Long: "\t\tLong: List all pinned code ids,\n",
Long: "List all pinned code ids",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -523,6 +534,7 @@ func GetCmdListPinnedCode() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "list codes")
Expand All @@ -534,7 +546,7 @@ func GetCmdListContractsByCreator() *cobra.Command {
cmd := &cobra.Command{
Use: "list-contracts-by-creator [creator]",
Short: "List all contracts by creator",
Long: "\t\tLong: List all contracts by creator,\n",
Long: "List all contracts by creator",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -563,6 +575,7 @@ func GetCmdListContractsByCreator() *cobra.Command {
}
return clientCtx.PrintProto(res)
},
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
Expand Down Expand Up @@ -650,6 +663,7 @@ func GetCmdQueryParams() *cobra.Command {

return clientCtx.PrintProto(&res.Params)
},
SilenceUsage: true,
}

flags.AddQueryFlagsToCmd(cmd)
Expand Down
5 changes: 5 additions & 0 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func GetTxCmd() *cobra.Command {
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
SilenceUsage: true,
}
txCmd.AddCommand(
StoreCodeCmd(),
Expand Down Expand Up @@ -76,6 +77,7 @@ func StoreCodeCmd() *cobra.Command {
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
Expand Down Expand Up @@ -202,6 +204,7 @@ $ %s tx wasm instantiate 1 '{"foo":"bar"}' --admin="$(%s keys show mykey -a)" \
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
Expand Down Expand Up @@ -262,6 +265,7 @@ $ %s tx wasm instantiate2 1 '{"foo":"bar"}' $(echo -n "testing" | xxd -ps) --adm
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
Expand Down Expand Up @@ -347,6 +351,7 @@ func ExecuteContractCmd() *cobra.Command {
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagAmount, "", "Coins to send to the contract along with command")
Expand Down

0 comments on commit 5e735f2

Please sign in to comment.