From a2d3b2a6e59d2a066a4497a170aca5cc99e05d51 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 9 May 2024 09:57:48 +0200 Subject: [PATCH] feat(client/v2): override short description in generated command (backport #20266) (#20269) Co-authored-by: John Letey Co-authored-by: Julien Robert --- client/v2/CHANGELOG.md | 1 + client/v2/autocli/common.go | 12 ++++++++++-- client/v2/autocli/msg.go | 6 +++++- client/v2/autocli/query.go | 6 +++++- client/v2/go.mod | 2 +- client/v2/go.sum | 4 ++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index 5e53959cf763..c86146bcb545 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands. * Note, the given command must have a `client.Context` in its context. * [#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. +* [#20266](https://github.com/cosmos/cosmos-sdk/pull/20266) Add ability to override the short description in AutoCLI-generated top-level commands. ### Bug Fixes diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 6db2e3326e45..de6b06d677a2 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -175,7 +175,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 } @@ -189,7 +193,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 } diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index bcf396db5c93..71796b9a49e9 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -38,7 +38,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. diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 03227f90e250..37756302018f 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -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 { diff --git a/client/v2/go.mod b/client/v2/go.mod index 63fd402c6554..113837041719 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/client/v2 go 1.21 require ( - cosmossdk.io/api v0.7.4 + cosmossdk.io/api v0.7.5 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/math v1.3.0 diff --git a/client/v2/go.sum b/client/v2/go.sum index 285e011ace8a..3567a0e69d81 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30= -cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= +cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= +cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=