From 8210b50647940c54aaa8fd481bd67d4681065159 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:43:48 +0100 Subject: [PATCH] fix(client/v2/autocli): prevent duplicate addition of customCommands (backport #22576) (#22615) Co-authored-by: violet <158512193+fastfadingviolets@users.noreply.github.com> Co-authored-by: Julien Robert --- client/v2/CHANGELOG.md | 3 +++ client/v2/autocli/common.go | 11 ++++++++++- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index 572d7817418a..b6f582c8d2fc 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v2.0.0-beta.6] - 2024-11-21 + ### Improvements * [#22443](https://github.com/cosmos/cosmos-sdk/pull/22443) Add keyring flags in query commands. @@ -44,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * [#21809](https://github.com/cosmos/cosmos-sdk/pull/21809) Correctly handle enhanced sub commands. +* [#22576](https://github.com/cosmos/cosmos-sdk/pull/22576) Fix duplicate command addition in `autocli` when custom enhanced command has a different name than module name ## [v2.0.0-beta.5] - 2024-09-18 diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 5c32f16ca32a..409198267cfd 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -140,7 +140,16 @@ func (b *Builder) enhanceCommandCommon( // if we have a custom command use that instead of generating one if custom, ok := customCmds[moduleName]; ok { - if hasModuleOptions { // check if we need to enhance the existing command + // Custom may not be called the same as its module, so we need to have a separate check here + if subCmd := findSubCommand(cmd, custom.Name()); subCmd != nil { + if hasModuleOptions { // check if we need to enhance the existing command + if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil { + return err + } + } + continue + } + if hasModuleOptions { // check if we need to enhance the new command if err := enhanceCustomCmd(b, custom, cmdType, modOpts); err != nil { return err } diff --git a/simapp/go.mod b/simapp/go.mod index c44f2024fb69..861ede729c18 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/client/v2 v2.0.0-beta.5 + cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/core v0.11.1 cosmossdk.io/depinject v1.1.0 diff --git a/simapp/go.sum b/simapp/go.sum index 781504268d3f..cb792d27d588 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -184,8 +184,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.5 h1:0LVv3nEByn//hFDIrYLs2WvsEU3HodOelh4SDHnA/1I= -cosmossdk.io/client/v2 v2.0.0-beta.5/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= +cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e h1:NqQEVIjRqSdsAfTI9uDRZ1oU/cQuCoAbUuIkndQM+Bo= +cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= 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.1 h1:h9WfBey7NAiFfIcUhDVNS503I2P2HdZLebJlUIs8LPA= diff --git a/tests/go.mod b/tests/go.mod index fd93147d964f..8e6358875941 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -36,7 +36,7 @@ require ( cloud.google.com/go/compute/metadata v0.5.0 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect - cosmossdk.io/client/v2 v2.0.0-beta.5 // indirect + cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/x/circuit v0.1.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect diff --git a/tests/go.sum b/tests/go.sum index 5b37ca3beb82..db9c826397af 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -184,8 +184,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.5 h1:0LVv3nEByn//hFDIrYLs2WvsEU3HodOelh4SDHnA/1I= -cosmossdk.io/client/v2 v2.0.0-beta.5/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= +cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e h1:NqQEVIjRqSdsAfTI9uDRZ1oU/cQuCoAbUuIkndQM+Bo= +cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= 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.1 h1:h9WfBey7NAiFfIcUhDVNS503I2P2HdZLebJlUIs8LPA=