From b51799844269634501600841c29d3af24774f9b2 Mon Sep 17 00:00:00 2001 From: Jeremy Lewi Date: Tue, 14 May 2024 15:26:43 -0700 Subject: [PATCH] Assets download shouldn't use CWD if there is no config file (#107) * When a user runs assets download they may not have created a .foyle/config.yaml file yet * As a result the ConfigDir will be the empty string and assets will be put into the local directory * To solve this if the ConfigFile is empty we return the default config directory. Fix #103 --- app/pkg/config/config.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/pkg/config/config.go b/app/pkg/config/config.go index b1c2a08..b78ec0d 100644 --- a/app/pkg/config/config.go +++ b/app/pkg/config/config.go @@ -194,7 +194,13 @@ func (c *Config) GetLogLevel() string { // GetConfigDir returns the configuration directory func (c *Config) GetConfigDir() string { - return filepath.Dir(viper.ConfigFileUsed()) + configFile := viper.ConfigFileUsed() + if configFile != "" { + return filepath.Dir(configFile) + } + + // Since there is no config file we will use the default config directory. + return binHome() } // IsValid validates the configuration and returns any errors.