Skip to content

Commit 451683b

Browse files
fix(client/v2): use (PREFIX)_HOME instead of NODE_HOME (backport #20964) (#20970)
Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent 28721bc commit 451683b

8 files changed

Lines changed: 30 additions & 11 deletions

File tree

client/v2/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
## [Unreleased]
3838

39+
## [v2.0.0-beta.4] - 2024-07-16
40+
41+
### Bug Fixes
42+
43+
* [#20964](https://github.com/cosmos/cosmos-sdk/pull/20964) Fix `GetNodeHomeDirectory` helper in `client/v2/helpers` to respect the `(PREFIX)_HOME` environment variable.
44+
3945
## [v2.0.0-beta.3] - 2024-07-15
4046

4147
### Features

client/v2/helpers/home.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import (
66
"strings"
77
)
88

9+
// EnvPrefix is the prefix for environment variables that are used by the CLI.
10+
// It should match the one used for viper in the CLI.
11+
var EnvPrefix = ""
12+
913
// GetNodeHomeDirectory gets the home directory of the node (where the config is located).
10-
// It parses the home flag if set if the `NODE_HOME` environment variable if set (and ignores name).
14+
// It parses the home flag if set if the `(PREFIX)_HOME` environment variable if set (and ignores name).
15+
// When no prefix is set, it reads the `NODE_HOME` environment variable.
1116
// Otherwise, it returns the default home directory given its name.
1217
func GetNodeHomeDirectory(name string) (string, error) {
1318
// get the home directory from the flag
@@ -21,12 +26,19 @@ func GetNodeHomeDirectory(name string) (string, error) {
2126
}
2227

2328
// get the home directory from the environment variable
24-
homeDir := os.Getenv("NODE_HOME")
29+
// to not clash with the $HOME system variable, when no prefix is set
30+
// we check the NODE_HOME environment variable
31+
homeDir, envHome := "", "HOME"
32+
if len(EnvPrefix) > 0 {
33+
homeDir = os.Getenv(EnvPrefix + "_" + envHome)
34+
} else {
35+
homeDir = os.Getenv("NODE_" + envHome)
36+
}
2537
if homeDir != "" {
2638
return filepath.Clean(homeDir), nil
2739
}
2840

29-
// return the default home directory
41+
// get user home directory
3042
userHomeDir, err := os.UserHomeDir()
3143
if err != nil {
3244
return "", err

docs/docs/learn/advanced/07-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ this will be more convenient:
163163

164164
```shell
165165
# define env variables in .env, .envrc etc
166-
NODE_HOME=<path to home>
166+
GAIA_HOME=<path to home>
167167
GAIA_NODE=<node address>
168168
GAIA_CHAIN_ID="testchain-1"
169169
GAIA_KEYRING_BACKEND="test"

simapp/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
cosmossdk.io/api v0.7.5
7-
cosmossdk.io/client/v2 v2.0.0-beta.3
7+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e
88
cosmossdk.io/collections v0.4.0 // indirect
99
cosmossdk.io/core v0.11.0
1010
cosmossdk.io/depinject v1.0.0-alpha.4

simapp/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
186186
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
187187
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
188188
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
189-
cosmossdk.io/client/v2 v2.0.0-beta.3 h1:+TTuH0DwQYsUq2JFAl3fDZzKq5gQG7nt3dAattkjFDU=
190-
cosmossdk.io/client/v2 v2.0.0-beta.3/go.mod h1:CZcL41HpJPOOayTCO28j8weNBQprG+SRiKX39votypo=
189+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e h1:hgYQOnWslxL8xyk93aqPNdFauHt9nOpmp/aGyzJMcsQ=
190+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e/go.mod h1:c753d0sBv3AQRx6X+BOKL1aGpKjZMTZAHGiLPbVi5TE=
191191
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
192192
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
193193
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=

simapp/simd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66

7+
clientv2helpers "cosmossdk.io/client/v2/helpers"
78
"cosmossdk.io/simapp"
89
"cosmossdk.io/simapp/simd/cmd"
910

@@ -12,7 +13,7 @@ import (
1213

1314
func main() {
1415
rootCmd := cmd.NewRootCmd()
15-
if err := svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome); err != nil {
16+
if err := svrcmd.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil {
1617
fmt.Fprintln(rootCmd.OutOrStderr(), err)
1718
os.Exit(1)
1819
}

tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
cloud.google.com/go/compute/metadata v0.2.3 // indirect
3838
cloud.google.com/go/iam v1.1.6 // indirect
3939
cloud.google.com/go/storage v1.38.0 // indirect
40-
cosmossdk.io/client/v2 v2.0.0-beta.3 // indirect
40+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e // indirect
4141
cosmossdk.io/collections v0.4.0 // indirect
4242
cosmossdk.io/x/circuit v0.1.1 // indirect
4343
filippo.io/edwards25519 v1.0.0 // indirect

tests/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
186186
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
187187
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
188188
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
189-
cosmossdk.io/client/v2 v2.0.0-beta.3 h1:+TTuH0DwQYsUq2JFAl3fDZzKq5gQG7nt3dAattkjFDU=
190-
cosmossdk.io/client/v2 v2.0.0-beta.3/go.mod h1:CZcL41HpJPOOayTCO28j8weNBQprG+SRiKX39votypo=
189+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e h1:hgYQOnWslxL8xyk93aqPNdFauHt9nOpmp/aGyzJMcsQ=
190+
cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e/go.mod h1:c753d0sBv3AQRx6X+BOKL1aGpKjZMTZAHGiLPbVi5TE=
191191
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
192192
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
193193
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=

0 commit comments

Comments
 (0)