Moves folder creation and error handling to loadConfig

This commit is contained in:
sloumdrone 2019-12-03 19:58:18 -08:00
parent 2900702313
commit 217b069172
2 changed files with 8 additions and 7 deletions

View File

@ -71,12 +71,7 @@ func homePath() string {
func xdgConfigPath() string {
configPath := os.Getenv("XDG_CONFIG_HOME")
if configPath == "" {
fp := filepath.Join(homePath(), ".config")
err := os.MkdirAll(fp, 0755)
if err != nil {
panic("Unable to create configuration directory: ~/.config")
}
return fp
return filepath.Join(homePath(), ".config")
}
return configPath
}

View File

@ -94,7 +94,13 @@ func lowerCaseOpt(opt, val string) string {
}
func loadConfig() error {
file, err := os.Open(bombadillo.Options["configlocation"] + "/.bombadillo.ini")
fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini")
err := os.MkdirAll(fp, 0755)
if err != nil {
return fmt.Errorf("configlocation cannot be written to or is invalid")
}
file, err := os.Open(fp)
if err != nil {
err = saveConfig()
if err != nil {