mirror of
https://github.com/cheat/cheat.git
synced 2024-11-21 13:31:36 +01:00
feat(config): refactor config path detection
Previously, failing other checks, on Unix and BSD systems, `config.Paths` would attempt to compute the user's home directory by reading the `HOME` environment variable. This change deprecates that approach with a call to `homedir.Dir`, which is used elsewhere throughout the application.
This commit is contained in:
parent
ec10244ebe
commit
efd09575df
@ -11,6 +11,12 @@ import (
|
||||
// system
|
||||
func Paths(sys string, envvars map[string]string) ([]string, error) {
|
||||
|
||||
// get the user's home directory
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("failed to get user home directory: %v", err)
|
||||
}
|
||||
|
||||
// if `CHEAT_CONFIG_PATH` is set, expand ~ and return it
|
||||
if confpath, ok := envvars["CHEAT_CONFIG_PATH"]; ok {
|
||||
|
||||
@ -32,10 +38,10 @@ func Paths(sys string, envvars map[string]string) ([]string, error) {
|
||||
paths = append(paths, path.Join(xdgpath, "/cheat/conf.yml"))
|
||||
}
|
||||
|
||||
// `HOME` will always be set on a POSIX-compliant system, though
|
||||
// if `XDG_CONFIG_HOME` is not set, search the user's home directory
|
||||
paths = append(paths, []string{
|
||||
path.Join(envvars["HOME"], ".config/cheat/conf.yml"),
|
||||
path.Join(envvars["HOME"], ".cheat/conf.yml"),
|
||||
path.Join(home, ".config/cheat/conf.yml"),
|
||||
path.Join(home, ".cheat/conf.yml"),
|
||||
}...)
|
||||
|
||||
return paths, nil
|
||||
|
Loading…
Reference in New Issue
Block a user