🐛 fix(cli): load config file only if it exists
- only load config file if it exists - prevents error when config file is not present
This commit is contained in:
committed by
Jeremiah Russell
parent
2af6df145f
commit
c1f7cf859a
@@ -428,17 +428,19 @@ fn get_config() -> Result<(Config, ClientConfig)> {
|
||||
let path = home_dir.join(".cull-gmail/cull-gmail.toml");
|
||||
log::info!("Loading config from {}", path.display());
|
||||
|
||||
let config_file = config::File::with_name(path.to_path_buf().to_str().unwrap());
|
||||
// let config_file = config_file.required(false);
|
||||
log::info!("Optional Config file {config_file:?}");
|
||||
|
||||
let configurations = config::Config::builder()
|
||||
let mut config_builder = config::Config::builder()
|
||||
.set_default("credential_file", "credential.json")?
|
||||
.set_default("config_root", "h:.cull-gmail")?
|
||||
.set_default("rules", "rules.toml")?
|
||||
.set_default("execute", true)?
|
||||
.set_default("token_cache_env", "CULL_GMAIL_TOKEN_CACHE")?
|
||||
.add_source(config_file)
|
||||
.set_default("token_cache_env", "CULL_GMAIL_TOKEN_CACHE")?;
|
||||
|
||||
if path.exists() {
|
||||
let config_file = config::File::with_name(path.to_path_buf().to_str().unwrap());
|
||||
log::info!("Config file {config_file:?}");
|
||||
config_builder = config_builder.add_source(config_file);
|
||||
}
|
||||
let configurations = config_builder
|
||||
.add_source(config::Environment::with_prefix("APP"))
|
||||
.build()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user