Skip to content

Commit a2d3b2a

Browse files
mergify[bot]johnleteyjulienrbrt
authored
feat(client/v2): override short description in generated command (backport #20266) (#20269)
Co-authored-by: John Letey <j@letey.de> Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent bd886bb commit a2d3b2a

6 files changed

Lines changed: 24 additions & 7 deletions

File tree

client/v2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4747
* [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands.
4848
* Note, the given command must have a `client.Context` in its context.
4949
* [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app.
50+
* [#20266](https://github.com/cosmos/cosmos-sdk/pull/20266) Add ability to override the short description in AutoCLI-generated top-level commands.
5051

5152
### Bug Fixes
5253

client/v2/autocli/common.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ func (b *Builder) enhanceCommandCommon(
175175
// enhanceQuery enhances the provided query command with the autocli commands for a module.
176176
func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error {
177177
if queryCmdDesc := modOpts.Query; queryCmdDesc != nil {
178-
subCmd := topLevelCmd(cmd.Context(), moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName))
178+
short := queryCmdDesc.Short
179+
if short == "" {
180+
short = fmt.Sprintf("Querying commands for the %s module", moduleName)
181+
}
182+
subCmd := topLevelCmd(cmd.Context(), moduleName, short)
179183
if err := builder.AddQueryServiceCommands(subCmd, queryCmdDesc); err != nil {
180184
return err
181185
}
@@ -189,7 +193,11 @@ func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOp
189193
// enhanceMsg enhances the provided msg command with the autocli commands for a module.
190194
func enhanceMsg(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error {
191195
if txCmdDesc := modOpts.Tx; txCmdDesc != nil {
192-
subCmd := topLevelCmd(cmd.Context(), moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName))
196+
short := txCmdDesc.Short
197+
if short == "" {
198+
short = fmt.Sprintf("Transactions commands for the %s module", moduleName)
199+
}
200+
subCmd := topLevelCmd(cmd.Context(), moduleName, short)
193201
if err := builder.AddMsgServiceCommands(subCmd, txCmdDesc); err != nil {
194202
return err
195203
}

client/v2/autocli/msg.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc
3838
for cmdName, subCmdDescriptor := range cmdDescriptor.SubCommands {
3939
subCmd := findSubCommand(cmd, cmdName)
4040
if subCmd == nil {
41-
subCmd = topLevelCmd(cmd.Context(), cmdName, fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service))
41+
short := cmdDescriptor.Short
42+
if cmdDescriptor.Short == "" {
43+
short = fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service)
44+
}
45+
subCmd = topLevelCmd(cmd.Context(), cmdName, short)
4246
}
4347

4448
// Add recursive sub-commands if there are any. This is used for nested services.

client/v2/autocli/query.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut
4141
for cmdName, subCmdDesc := range cmdDescriptor.SubCommands {
4242
subCmd := findSubCommand(cmd, cmdName)
4343
if subCmd == nil {
44-
subCmd = topLevelCmd(cmd.Context(), cmdName, fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service))
44+
short := cmdDescriptor.Short
45+
if short == "" {
46+
short = fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service)
47+
}
48+
subCmd = topLevelCmd(cmd.Context(), cmdName, short)
4549
}
4650

4751
if err := b.AddQueryServiceCommands(subCmd, subCmdDesc); err != nil {

client/v2/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module cosmossdk.io/client/v2
33
go 1.21
44

55
require (
6-
cosmossdk.io/api v0.7.4
6+
cosmossdk.io/api v0.7.5
77
cosmossdk.io/core v0.11.0
88
cosmossdk.io/depinject v1.0.0-alpha.4
99
cosmossdk.io/math v1.3.0

client/v2/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
3-
cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30=
4-
cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
3+
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
4+
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
55
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
66
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
77
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=

0 commit comments

Comments
 (0)