1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Clean up cfg error handling a bit

Pass in the actual file being used, rather than hardcoded `config.yaml`
Differences between two error messages are not that distinct
Centralize on one and clean up all the `isCustomConfig` tracking
This commit is contained in:
Sean Smith
2019-09-12 20:28:24 -04:00
parent 8cf50fe92c
commit 9f81207037
4 changed files with 9 additions and 27 deletions

View File

@@ -84,17 +84,12 @@ func WtfConfigDir() (string, error) {
}
// LoadWtfConfigFile loads the specified config file
func LoadWtfConfigFile(filePath string, isCustomConfig bool) *config.Config {
func LoadWtfConfigFile(filePath string) *config.Config {
absPath, _ := expandHomeDir(filePath)
cfg, err := config.ParseYamlFile(absPath)
if err != nil {
if isCustomConfig {
displayWtfCustomConfigFileLoadError(err)
} else {
displayWtfConfigFileLoadError(err)
}
displayWtfConfigFileLoadError(absPath, err)
os.Exit(1)
}

View File

@@ -42,19 +42,8 @@ func displayWtfConfigDirCreateError(err error) {
displayError(err)
}
func displayWtfConfigFileLoadError(err error) {
fmt.Printf("\n%s Could not load '%s'.\n", aurora.Red("ERROR"), aurora.Yellow(WtfConfigFile))
fmt.Println()
fmt.Println("This could mean one of two things:")
fmt.Println()
fmt.Printf(" 1. Your %s file is missing. Check in %s to see if %s is there.\n", aurora.Yellow(WtfConfigFile), aurora.Yellow("~/.config/wtf/"), aurora.Yellow(WtfConfigFile))
fmt.Printf(" 2. Your %s file has a syntax error. Try running it through http://www.yamllint.com to check for errors.\n", aurora.Yellow(WtfConfigFile))
fmt.Println()
displayError(err)
}
func displayWtfCustomConfigFileLoadError(err error) {
fmt.Printf("\n%s Could not load '%s'.\n", aurora.Red("ERROR"), aurora.Yellow(WtfConfigFile))
func displayWtfConfigFileLoadError(path string, err error) {
fmt.Printf("\n%s Could not load '%s'.\n", aurora.Red("ERROR"), aurora.Yellow(path))
fmt.Println()
fmt.Println("This could mean one of two things:")
fmt.Println()