From e80579102584eaa61988172efc5a1969b9f02134 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 18 Dec 2024 10:39:15 +0100 Subject: [PATCH] readme --- client/v2/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ x/circuit/autocli.go | 13 ++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/client/v2/README.md b/client/v2/README.md index b4c2666850ee..0176733c2f67 100644 --- a/client/v2/README.md +++ b/client/v2/README.md @@ -161,6 +161,48 @@ Then the command can be used as follows, instead of having to specify the `--add query auth account cosmos1abcd...xyz ``` +#### Flattened Fields in Positional Arguments + +AutoCLI also supports flattening nested message fields as positional arguments. This means you can access nested fields +using dot notation in the `ProtoField` parameter. This is particularly useful when you want to directly set nested +message fields as positional arguments. + +For example, if you have a nested message structure like this: + +```protobuf +message Permissions { + string level = 1; + repeated string limit_type_urls = 2; +} + +message MsgAuthorizeCircuitBreaker { + string grantee = 1; + Permissions permissions = 2; +} +``` + +You can flatten the fields in your AutoCLI configuration: + +```go +{ + RpcMethod: "AuthorizeCircuitBreaker", + Use: "authorize ", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "grantee"}, + {ProtoField: "permissions.level"}, + {ProtoField: "permissions.limit_type_urls"}, + }, +} +``` + +This allows users to provide values for nested fields directly as positional arguments: + +```bash + tx circuit authorize cosmos1... super-admin "/cosmos.bank.v1beta1.MsgSend,/cosmos.bank.v1beta1.MsgMultiSend" +``` + +Instead of having to provide a complex JSON structure for nested fields, flattening makes the CLI more user-friendly by allowing direct access to nested fields. + #### Customising Flag Names By default, `autocli` generates flag names based on the names of the fields in your protobuf message. However, you can customise the flag names by providing a `FlagOptions`. This parameter allows you to specify custom names for flags based on the names of the message fields. diff --git a/x/circuit/autocli.go b/x/circuit/autocli.go index a1cb8ada74e6..b20759b3bf04 100644 --- a/x/circuit/autocli.go +++ b/x/circuit/autocli.go @@ -37,16 +37,15 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcCommandOptions: []*autocliv1.RpcCommandOptions{ { RpcMethod: "AuthorizeCircuitBreaker", - Use: "authorize --from ", + Use: "authorize --from ", Short: "Authorize an account to trip the circuit breaker.", - Long: `Authorize an account to trip the circuit breaker. -"SOME_MSGS" = 1, -"ALL_MSGS" = 2, -"SUPER_ADMIN" = 3,`, - Example: fmt.Sprintf(`%s tx circuit authorize [address] '{"level":1,"limit_type_urls":["/cosmos.bank.v1beta1.MsgSend", "/cosmos.bank.v1beta1.MsgMultiSend"]}'"`, version.AppName), + Long: `Authorize an account to trip the circuit breaker. Level can be: some-msgs, all-msgs or super-admin.`, + Example: fmt.Sprintf(`%s tx circuit authorize [address] super-admin "/cosmos.bank.v1beta1.MsgSend,/cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "grantee"}, - {ProtoField: "permissions"}, // TODO(@julienrbrt) Support flattening msg for setting each field as a positional arg + {ProtoField: "permissions"}, + {ProtoField: "permissions.level"}, + {ProtoField: "permissions.limit_type_urls"}, }, }, {