Skip to content

Commit

Permalink
fix(cli): home flag gets ignored when running help (#11645)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Apr 21, 2022
1 parent 2f6a3e6 commit 2c94c2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions simapp/simd/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down

0 comments on commit 2c94c2e

Please sign in to comment.