Skip to content

Commit 156b425

Browse files
julienrbrtmergify[bot]
authored andcommitted
fix(client/v2): use (PREFIX)_HOME instead of NODE_HOME (#20964)
(cherry picked from commit 6708818) # Conflicts: # client/v2/CHANGELOG.md # simapp/v2/simdv2/main.go
1 parent 28721bc commit 156b425

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

client/v2/CHANGELOG.md

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

3737
## [Unreleased]
3838

39+
<<<<<<< HEAD
40+
=======
41+
<!-- ## [v2.1.0-rc.1] to be tagged after v0.51 final or in SDK agnostic version -->
42+
43+
### Features
44+
45+
* [#18626](https://github.com/cosmos/cosmos-sdk/pull/18626) Support for off-chain signing and verification of a file.
46+
* [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals.
47+
48+
### API Breaking Changes
49+
50+
* [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)).
51+
52+
### Bug Fixes
53+
54+
* [#20964](https://github.com/cosmos/cosmos-sdk/pull/20964) Fix `GetNodeHomeDirectory` helper in `client/v2/helpers` to respect the `(PREFIX)_HOME` environment variable.
55+
56+
>>>>>>> 670881847 (fix(client/v2): use (PREFIX)_HOME instead of NODE_HOME (#20964))
3957
## [v2.0.0-beta.3] - 2024-07-15
4058

4159
### 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/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
}

simapp/v2/simdv2/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
clientv2helpers "cosmossdk.io/client/v2/helpers"
8+
"cosmossdk.io/core/transaction"
9+
serverv2 "cosmossdk.io/server/v2"
10+
"cosmossdk.io/simapp/v2"
11+
"cosmossdk.io/simapp/v2/simdv2/cmd"
12+
)
13+
14+
func main() {
15+
rootCmd := cmd.NewRootCmd[transaction.Tx]()
16+
if err := serverv2.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil {
17+
fmt.Fprintln(rootCmd.OutOrStderr(), err)
18+
os.Exit(1)
19+
}
20+
}

0 commit comments

Comments
 (0)