refactor(cli): Standardize Use field convention and update readme (#21369)

This commit is contained in:
Lucas Francisco López
2024-08-21 08:36:34 +00:00
committed by GitHub
parent 95dcf845c3
commit bdb9232ed8
56 changed files with 200 additions and 173 deletions
+5 -5
View File
@@ -82,7 +82,7 @@ func getCodecInterfaces() *cobra.Command {
// getCodecInterfaceImpls creates and returns a new cmd used for listing all registered implementations of a given interface on the application codec.
func getCodecInterfaceImpls() *cobra.Command {
return &cobra.Command{
Use: "list-implementations [interface]",
Use: "list-implementations <interface>",
Short: "List the registered type URLs for the provided interface",
Long: "List the registered type URLs that can be used for the provided interface name using the application codec",
Example: fmt.Sprintf("%s debug codec list-implementations cosmos.crypto.PubKey", version.AppName),
@@ -109,7 +109,7 @@ func getPubKeyFromString(ctx client.Context, pkstr string) (cryptotypes.PubKey,
func PubkeyCmd() *cobra.Command {
return &cobra.Command{
Use: "pubkey [pubkey]",
Use: "pubkey <pubkey>",
Short: "Decode a pubkey from proto JSON",
Long: "Decode a pubkey from proto JSON and display it's address.",
Example: fmt.Sprintf(`%s debug pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AurroA7jvfPd1AadmmOvWM2rJSwipXfRf8yD6pLbA2DJ"}'`, version.AppName),
@@ -181,7 +181,7 @@ func getPubKeyFromRawString(pkstr, keytype string) (cryptotypes.PubKey, error) {
func PubkeyRawCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pubkey-raw [pubkey] -t [{ed25519, secp256k1}]",
Use: "pubkey-raw <pubkey> [-t {ed25519, secp256k1}]",
Short: "Decode a ED25519 or secp256k1 pubkey from hex, base64, or bech32",
Long: "Decode a pubkey from hex, base64, or bech32.",
Example: fmt.Sprintf(`
@@ -247,7 +247,7 @@ func PubkeyRawCmd() *cobra.Command {
func AddrCmd() *cobra.Command {
return &cobra.Command{
Use: "addr [address]",
Use: "addr <address>",
Short: "Convert an address between hex and bech32",
Example: fmt.Sprintf("%s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg", version.AppName),
Args: cobra.ExactArgs(1),
@@ -303,7 +303,7 @@ func AddrCmd() *cobra.Command {
func RawBytesCmd() *cobra.Command {
return &cobra.Command{
Use: "raw-bytes [raw-bytes]",
Use: "raw-bytes <raw-bytes>",
Short: "Convert raw bytes output (eg. [10 21 13 255]) to hex",
Long: "Convert raw-bytes to hex.",
Example: fmt.Sprintf("%s debug raw-bytes [72 101 108 108 111 44 32 112 108 97 121 103 114 111 117 110 100]", version.AppName),
+2 -2
View File
@@ -25,7 +25,7 @@ var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
},
{
RpcMethod: "GetBlockByHeight",
Use: "block-by-height [height]",
Use: "block-by-height <height>",
Short: "Query for a committed block by height",
Long: "Query for a specific committed block using the CometBFT RPC `block_by_height` method",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
@@ -38,7 +38,7 @@ var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
},
{
RpcMethod: "GetValidatorSetByHeight",
Use: "validator-set-by-height [height]",
Use: "validator-set-by-height <height>",
Short: "Query for a validator set by height",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
},
+1 -1
View File
@@ -37,7 +37,7 @@ const (
// ShowKeysCmd shows key information for a given key name.
func ShowKeysCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show [name_or_address [name_or_address...]]",
Use: "show <name_or_address> [name_or_address...]",
Short: "Retrieve key information by name or address",
Long: `Display keys details. If multiple names or addresses are provided,
then an ephemeral multisig key will be created under the name "multi"
+24
View File
@@ -131,6 +131,30 @@ AutoCLI can create a gov proposal of any tx by simply setting the `GovProposal`
Users can however use the `--no-proposal` flag to disable the proposal creation (which is useful if the authority isn't the gov module on a chain).
:::
### Conventions for the `Use` field in Cobra
According to the [Cobra documentation](https://pkg.go.dev/github.com/spf13/cobra#Command) the following conventions should be followed for the `Use` field in Cobra commands:
1. **Required arguments**:
* Should not be enclosed in brackets. They can be enclosed in angle brackets `< >` for clarity.
* Example: `command <required_argument>`
2. **Optional arguments**:
* Should be enclosed in square brackets `[ ]`.
* Example: `command [optional_argument]`
3. **Alternative (mutually exclusive) arguments**:
* Should be enclosed in curly braces `{ }`.
* Example: `command {-a | -b}` for required alternatives.
* Example: `command [-a | -b]` for optional alternatives.
4. **Multiple arguments**:
* Indicated with `...` after the argument.
* Example: `command argument...`
5. **Combination of options**:
* Example: `command [-F file | -D dir]... [-f format] profile`
### Specifying Subcommands
By default, `autocli` generates a command for each method in your gRPC service. However, you can specify subcommands to group related commands together. To specify subcommands, use the `autocliv1.ServiceCommandDescriptor` struct.
+4 -4
View File
@@ -41,7 +41,7 @@ var bankAutoCLI = &autocliv1.ServiceCommandDescriptor{
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Send",
Use: "send [from_key_or_address] [to_address] [amount] [flags]",
Use: "send <from_key_or_address> <to_address> <amount> [flags]",
Short: "Send coins from one account to another",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}},
},
@@ -64,7 +64,7 @@ func TestMsg(t *testing.T) {
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Send",
Use: "send [from_key_or_address] [to_address] [amount] [flags]",
Use: "send <from_key_or_address> <to_address> <amount> [flags]",
Short: "Send coins from one account to another",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}},
},
@@ -83,7 +83,7 @@ func TestMsg(t *testing.T) {
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Send",
Use: "send [from_key_or_address] [to_address] [amount] [flags]",
Use: "send <from_key_or_address> <to_address> <amount> [flags]",
Short: "Send coins from one account to another",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}},
// from_address should be automatically added
@@ -104,7 +104,7 @@ func TestMsg(t *testing.T) {
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Send",
Use: "send [from_key_or_address] [to_address] [amount] [flags]",
Use: "send <from_key_or_address> <to_address> <amount> [flags]",
Short: "Send coins from one account to another",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}},
FlagOptions: map[string]*autocliv1.FlagOptions{
+1 -1
View File
@@ -1,7 +1,7 @@
Send coins from one account to another
Usage:
test send [from_key_or_address] [to_address] [amount] [flags]
test send <from_key_or_address> <to_address> <amount> [flags]
Flags:
-a, --account-number uint The account number of the signing account (offline mode only)