Skip to content

Commit

Permalink
feat(client/v2): override short description in generated command (#20266
Browse files Browse the repository at this point in the history
)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
johnletey and coderabbitai[bot] authored May 3, 2024
1 parent f4b5349 commit 7a505ad
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 84 deletions.
235 changes: 155 additions & 80 deletions api/cosmos/autocli/v1/options.pulsar.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18626](https://github.com/cosmos/cosmos-sdk/pull/18626) Support for off-chain signing and verification of a file.
* [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals.
* [#19039](https://github.com/cosmos/cosmos-sdk/pull/19039) Add support for pubkey in autocli.
* [#20266](https://github.com/cosmos/cosmos-sdk/pull/20266) Ability to override the short description in AutoCLI-generated top-level commands.

### Improvements

Expand Down
12 changes: 10 additions & 2 deletions client/v2/autocli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func (b *Builder) enhanceCommandCommon(
// enhanceQuery enhances the provided query command with the autocli commands for a module.
func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error {
if queryCmdDesc := modOpts.Query; queryCmdDesc != nil {
subCmd := topLevelCmd(cmd.Context(), moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName))
short := queryCmdDesc.Short
if short == "" {
short = fmt.Sprintf("Querying commands for the %s module", moduleName)
}
subCmd := topLevelCmd(cmd.Context(), moduleName, short)
if err := builder.AddQueryServiceCommands(subCmd, queryCmdDesc); err != nil {
return err
}
Expand All @@ -188,7 +192,11 @@ func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOp
// enhanceMsg enhances the provided msg command with the autocli commands for a module.
func enhanceMsg(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error {
if txCmdDesc := modOpts.Tx; txCmdDesc != nil {
subCmd := topLevelCmd(cmd.Context(), moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName))
short := txCmdDesc.Short
if short == "" {
short = fmt.Sprintf("Transactions commands for the %s module", moduleName)
}
subCmd := topLevelCmd(cmd.Context(), moduleName, short)
if err := builder.AddMsgServiceCommands(subCmd, txCmdDesc); err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc
for cmdName, subCmdDescriptor := range cmdDescriptor.SubCommands {
subCmd := findSubCommand(cmd, cmdName)
if subCmd == nil {
subCmd = topLevelCmd(cmd.Context(), cmdName, fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service))
short := cmdDescriptor.Short
if cmdDescriptor.Short == "" {
short = fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service)
}
subCmd = topLevelCmd(cmd.Context(), cmdName, short)
}

// Add recursive sub-commands if there are any. This is used for nested services.
Expand Down
6 changes: 5 additions & 1 deletion client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut
for cmdName, subCmdDesc := range cmdDescriptor.SubCommands {
subCmd := findSubCommand(cmd, cmdName)
if subCmd == nil {
subCmd = topLevelCmd(cmd.Context(), cmdName, fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service))
short := cmdDescriptor.Short
if short == "" {
short = fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service)
}
subCmd = topLevelCmd(cmd.Context(), cmdName, short)
}

if err := b.AddQueryServiceCommands(subCmd, subCmdDesc); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions proto/cosmos/autocli/v1/options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ message ServiceCommandDescriptor {
// exists, or enhance the existing command. If set to true, the custom command will be enhanced with the services from
// gRPC. otherwise when a custom command exists, no commands will be generated for the service.
bool enhance_custom_command = 4;

// short is an optional parameter used to override the short description of the auto generated command.
string short = 5;
}

// RpcCommandOptions specifies options for commands generated from protobuf
Expand Down

0 comments on commit 7a505ad

Please sign in to comment.