Skip to content

Commit cc1a1c8

Browse files
authored
fix: --home flag parsing (#10226)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #XXXX <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [x] reviewed state machine logic - [x] reviewed API design and naming - [x] reviewed documentation is accurate - [x] reviewed tests and test coverage - [x] manually tested (if applicable)
1 parent 3f024bf commit cc1a1c8

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
124124
* [\#10262](https://github.com/cosmos/cosmos-sdk/pull/10262) Remove unnecessary logging in `x/feegrant` simulation.
125125

126126
### Bug Fixes
127+
128+
* (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing.
127129
* [#10180](https://github.com/cosmos/cosmos-sdk/issues/10180) Documentation: make references to Cosmos SDK consistent
128130
* (store) [#10218](https://github.com/cosmos/cosmos-sdk/pull/10218) Charge gas even when there are no entries while seeking.
129131
* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.

client/cmd.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont
9393
clientCtx = clientCtx.WithOutputFormat(output)
9494
}
9595

96+
if clientCtx.HomeDir == "" || flagSet.Changed(flags.FlagHome) {
97+
homeDir, _ := flagSet.GetString(flags.FlagHome)
98+
clientCtx = clientCtx.WithHomeDir(homeDir)
99+
}
100+
96101
if !clientCtx.Simulate || flagSet.Changed(flags.FlagDryRun) {
97102
dryRun, _ := flagSet.GetBool(flags.FlagDryRun)
98103
clientCtx = clientCtx.WithSimulation(dryRun)
@@ -249,17 +254,6 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
249254
return clientCtx, nil
250255
}
251256

252-
// ReadHomeFlag checks if home flag is changed. If this is a case, we update
253-
// HomeDir field of Client Context.
254-
func ReadHomeFlag(clientCtx Context, cmd *cobra.Command) Context {
255-
if cmd.Flags().Changed(flags.FlagHome) {
256-
rootDir, _ := cmd.Flags().GetString(flags.FlagHome)
257-
clientCtx = clientCtx.WithHomeDir(rootDir)
258-
}
259-
260-
return clientCtx
261-
}
262-
263257
// GetClientQueryContext returns a Context from a command with fields set based on flags
264258
// defined in AddQueryFlagsToCmd. An error is returned if any flag query fails.
265259
//

client/keys/list_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func Test_runListCmd(t *testing.T) {
5959
cmd.SetArgs([]string{
6060
fmt.Sprintf("--%s=%s", flags.FlagHome, tt.kbDir),
6161
fmt.Sprintf("--%s=false", flagListNames),
62-
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
6362
})
6463

6564
if err := cmd.ExecuteContext(ctx); (err != nil) != tt.wantErr {
@@ -69,7 +68,6 @@ func Test_runListCmd(t *testing.T) {
6968
cmd.SetArgs([]string{
7069
fmt.Sprintf("--%s=%s", flags.FlagHome, tt.kbDir),
7170
fmt.Sprintf("--%s=true", flagListNames),
72-
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
7371
})
7472

7573
if err := cmd.ExecuteContext(ctx); (err != nil) != tt.wantErr {

simapp/simd/cmd/root.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
5656
cmd.SetOut(cmd.OutOrStdout())
5757
cmd.SetErr(cmd.ErrOrStderr())
5858

59-
initClientCtx = client.ReadHomeFlag(initClientCtx, cmd)
59+
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
60+
if err != nil {
61+
return err
62+
}
6063

61-
initClientCtx, err := config.ReadFromClientConfig(initClientCtx)
64+
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
6265
if err != nil {
6366
return err
6467
}

x/genutil/client/cli/init.go

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
8080

8181
serverCtx := server.GetServerContextFromCmd(cmd)
8282
config := serverCtx.Config
83-
84-
clientCtx = client.ReadHomeFlag(clientCtx, cmd)
8583
config.SetRoot(clientCtx.HomeDir)
8684

8785
chainID, _ := cmd.Flags().GetString(flags.FlagChainID)

0 commit comments

Comments
 (0)