diff --git a/context/config_file.go b/context/config_file.go index 5236930a1..49b0bf559 100644 --- a/context/config_file.go +++ b/context/config_file.go @@ -8,7 +8,6 @@ import ( "os" "path" - "github.com/mitchellh/go-homedir" "gopkg.in/yaml.v3" ) @@ -36,11 +35,9 @@ func parseConfigFile(fn string) (*configEntry, error) { return parseConfig(f) } -// ParseDefaultConfig reads the configuration from ~/.config/gh +// ParseDefaultConfig reads the configuration file func ParseDefaultConfig() (*configEntry, error) { - // FIXME: this duplicates fsContext.configFile - fn, _ := homedir.Expand("~/.config/gh") - return parseConfigFile(fn) + return parseConfigFile(configFile()) } func parseConfig(r io.Reader) (*configEntry, error) { @@ -75,7 +72,7 @@ func parseConfig(r io.Reader) (*configEntry, error) { // If ~/.config/gh is a file, convert it to a directory and place the file // into ~/.config/gh/config.yml func migrateConfigFile() { - p, _ := homedir.Expand("~/.config/gh") + p := ConfigDir() fi, err := os.Stat(p) if err != nil { // This means the file doesn't exist, and that is fine. return diff --git a/context/context.go b/context/context.go index 20a921ffc..e5d74634c 100644 --- a/context/context.go +++ b/context/context.go @@ -1,6 +1,7 @@ package context import ( + "path" "strings" "github.com/github/gh-cli/git" @@ -39,14 +40,18 @@ type fsContext struct { authToken string } -func (c *fsContext) configFile() string { - dir, _ := homedir.Expand("~/.config/gh/config.yml") +func ConfigDir() string { + dir, _ := homedir.Expand("~/.config/gh") return dir } +func configFile() string { + return path.Join(ConfigDir(), "config.yml") +} + func (c *fsContext) getConfig() (*configEntry, error) { if c.config == nil { - entry, err := parseOrSetupConfigFile(c.configFile()) + entry, err := parseOrSetupConfigFile(configFile()) if err != nil { return nil, err } diff --git a/main.go b/main.go index f09edb18d..726b50784 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,15 @@ package main import ( "fmt" "os" + "path" "strings" "github.com/github/gh-cli/command" + "github.com/github/gh-cli/context" "github.com/github/gh-cli/update" "github.com/github/gh-cli/utils" "github.com/mattn/go-isatty" "github.com/mgutz/ansi" - "github.com/mitchellh/go-homedir" ) var updaterEnabled = "" @@ -61,9 +62,6 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) { } repo := updaterEnabled - stateFilePath, err := homedir.Expand("~/.config/gh/state.yml") - if err != nil { - return nil, err - } + stateFilePath := path.Join(context.ConfigDir(), "state.yml") return update.CheckForUpdate(client, stateFilePath, repo, currentVersion) }