-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Julien Robert <[email protected]>
- Loading branch information
1 parent
0e6db14
commit e4c342e
Showing
18 changed files
with
208 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package helpers | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// GetNodeHomeDirectory gets the home directory of the node (where the config is located). | ||
// It parses the home flag if set if the `NODE_HOME` environment variable if set (and ignores name). | ||
// Otherwise, it returns the default home directory given its name. | ||
func GetNodeHomeDirectory(name string) (string, error) { | ||
// get the home directory from the flag | ||
args := os.Args | ||
for i := 0; i < len(args); i++ { | ||
if args[i] == "--home" && i+1 < len(args) { | ||
return filepath.Clean(args[i+1]), nil | ||
} else if strings.HasPrefix(args[i], "--home=") { | ||
return filepath.Clean(args[i][7:]), nil | ||
} | ||
} | ||
|
||
// get the home directory from the environment variable | ||
homeDir := os.Getenv("NODE_HOME") | ||
if homeDir != "" { | ||
return filepath.Clean(homeDir), nil | ||
} | ||
|
||
// return the default home directory | ||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return filepath.Join(userHomeDir, name), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.