mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat: print config error
This commit is contained in:
parent
f54c9eb514
commit
b623c5f190
|
@ -33,6 +33,10 @@ const (
|
||||||
EnableHyperlink Property = "enable_hyperlink"
|
EnableHyperlink Property = "enable_hyperlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func printConfigError(err error) {
|
||||||
|
fmt.Println("Oh My Posh Error:\n", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// GetConfig returns the default configuration including possible user overrides
|
// GetConfig returns the default configuration including possible user overrides
|
||||||
func GetConfig(env environmentInfo) *Config {
|
func GetConfig(env environmentInfo) *Config {
|
||||||
cfg, err := loadConfig(env)
|
cfg, err := loadConfig(env)
|
||||||
|
@ -49,6 +53,7 @@ func loadConfig(env environmentInfo) (*Config, error) {
|
||||||
return nil, errors.New("NO CONFIG")
|
return nil, errors.New("NO CONFIG")
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
|
printConfigError(err)
|
||||||
return nil, errors.New("INVALID CONFIG PATH")
|
return nil, errors.New("INVALID CONFIG PATH")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +66,13 @@ func loadConfig(env environmentInfo) (*Config, error) {
|
||||||
|
|
||||||
err := config.LoadFiles(configFile)
|
err := config.LoadFiles(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
printConfigError(err)
|
||||||
return nil, errors.New("UNABLE TO OPEN CONFIG")
|
return nil, errors.New("UNABLE TO OPEN CONFIG")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = config.BindStruct("", &cfg)
|
err = config.BindStruct("", &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
printConfigError(err)
|
||||||
return nil, errors.New("INVALID CONFIG")
|
return nil, errors.New("INVALID CONFIG")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +90,7 @@ func exportConfig(configFile, format string) string {
|
||||||
|
|
||||||
err := config.LoadFiles(configFile)
|
err := config.LoadFiles(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
printConfigError(err)
|
||||||
return fmt.Sprintf("INVALID CONFIG:\n\n%s", err.Error())
|
return fmt.Sprintf("INVALID CONFIG:\n\n%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +104,7 @@ func exportConfig(configFile, format string) string {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
_, err = config.DumpTo(buf, format)
|
_, err = config.DumpTo(buf, format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
printConfigError(err)
|
||||||
return "UNABLE TO DUMP CONFIG"
|
return "UNABLE TO DUMP CONFIG"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue