From 2c94c2e1b49003c7a63b42283eb28258d474ab1d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 21 Apr 2022 15:27:31 +0200 Subject: [PATCH] fix(cli): home flag gets ignored when running help (#11645) --- CHANGELOG.md | 1 + client/cmd_test.go | 9 +++++++++ simapp/simd/cmd/cmd_test.go | 19 +++++++++++++++++++ simapp/simd/cmd/root.go | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5df8d99d77c..7f7d1c1957d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -211,6 +211,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * [\#11693](https://github.com/cosmos/cosmos-sdk/pull/11693) Add validation for gentx cmd. +* [\#11645](https://github.com/cosmos/cosmos-sdk/pull/11645) Fix `--home` flag ignored when running help. * [\#11558](https://github.com/cosmos/cosmos-sdk/pull/11558) Fix `--dry-run` not working when using tx command. * [\#11354](https://github.com/cosmos/cosmos-sdk/pull/11355) Added missing pagination flag for `bank q total` query. * [\#11197](https://github.com/cosmos/cosmos-sdk/pull/11197) Signing with multisig now works with multisig address which is not in the keyring. diff --git a/client/cmd_test.go b/client/cmd_test.go index 65161fe4752b..81d5719ccfb6 100644 --- a/client/cmd_test.go +++ b/client/cmd_test.go @@ -70,6 +70,7 @@ func TestSetCmdClientContextHandler(t *testing.T) { } c.Flags().String(flags.FlagChainID, "", "network chain ID") + c.Flags().String(flags.FlagHome, "", "home dir") return c } @@ -91,6 +92,14 @@ func TestSetCmdClientContextHandler(t *testing.T) { fmt.Sprintf("--%s=new-chain-id", flags.FlagChainID), }, }, + { + "flags set with space", + initClientCtx.WithHomeDir("/tmp/dir"), + []string{ + fmt.Sprintf("--%s", flags.FlagHome), + "/tmp/dir", + }, + }, } for _, tc := range testCases { diff --git a/simapp/simd/cmd/cmd_test.go b/simapp/simd/cmd/cmd_test.go index 0e2a291e9c74..ab9d8de71064 100644 --- a/simapp/simd/cmd/cmd_test.go +++ b/simapp/simd/cmd/cmd_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client/flags" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/simd/cmd" @@ -22,3 +23,21 @@ func TestInitCmd(t *testing.T) { require.NoError(t, svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome)) } + +func TestHomeFlagRegistration(t *testing.T) { + homeDir := "/tmp/foo" + + rootCmd, _ := cmd.NewRootCmd() + + rootCmd.SetArgs([]string{ + "query", + fmt.Sprintf("--%s", flags.FlagHome), + homeDir, + }) + + require.NoError(t, svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome)) + + result, err := rootCmd.Flags().GetString(flags.FlagHome) + require.NoError(t, err) + require.Equal(t, result, homeDir) +} diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 9ae7f10a7b48..978180630409 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -192,7 +192,7 @@ func queryCommand() *cobra.Command { Use: "query", Aliases: []string{"q"}, Short: "Querying subcommands", - DisableFlagParsing: true, + DisableFlagParsing: false, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } @@ -215,7 +215,7 @@ func txCommand() *cobra.Command { cmd := &cobra.Command{ Use: "tx", Short: "Transactions subcommands", - DisableFlagParsing: true, + DisableFlagParsing: false, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, }