Bail if config file contains 'config_file_path'

This commit is contained in:
arriven 2022-10-03 21:23:42 +03:00
parent 8fa8eb9767
commit 59f1091c5e

View File

@ -257,6 +257,11 @@ impl Opt {
Ok(config) => { Ok(config) => {
// If the file is successfully read, we deserialize it with `toml`. // If the file is successfully read, we deserialize it with `toml`.
let opt_from_config = toml::from_slice::<Opt>(&config)?; let opt_from_config = toml::from_slice::<Opt>(&config)?;
// Return an error if config file contains 'config_file_path'
// Using that key in the config file doesn't make sense bc it creates a logical loop (config file referencing itself)
if opt_from_config.config_file_path.is_some() {
anyhow::bail!("`config_file_path` is not supported in config file")
}
// We inject the values from the toml in the corresponding env vars if needs be. Doing so, we respect the priority toml < env vars < cli args. // We inject the values from the toml in the corresponding env vars if needs be. Doing so, we respect the priority toml < env vars < cli args.
opt_from_config.export_to_env(); opt_from_config.export_to_env();
// Once injected we parse the cli args once again to take the new env vars into scope. // Once injected we parse the cli args once again to take the new env vars into scope.