Add quotes around file name and change error message

This commit is contained in:
mlemesle 2022-09-22 09:44:28 +02:00
parent 56d72d4493
commit 248d727e61
2 changed files with 11 additions and 14 deletions

View File

@ -119,7 +119,7 @@ pub fn print_launch_resume(opt: &Opt, user: &str, config_read_from: Option<PathB
eprintln!("{}", ascii_name); eprintln!("{}", ascii_name);
eprintln!( eprintln!(
"Config file path:\t{}", "Config file path:\t{:?}",
config_read_from config_read_from
.map(|config_file_path| config_file_path.display().to_string()) .map(|config_file_path| config_file_path.display().to_string())
.unwrap_or_else(|| "none".to_string()) .unwrap_or_else(|| "none".to_string())

View File

@ -256,21 +256,18 @@ impl Opt {
match std::fs::read(&config_file_path) { match std::fs::read(&config_file_path) {
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`.
match toml::from_slice::<Opt>(&config) { let opt_from_config = toml::from_slice::<Opt>(&config)?;
Ok(opt_from_config) => { // 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. opts = Opt::parse();
opts = Opt::parse(); config_read_from = Some(config_file_path);
config_read_from = Some(config_file_path);
}
// If we have an error deserializing the file defined by the user.
Err(err) if opts.config_file_path.is_some() => anyhow::bail!(err),
_ => (),
}
} }
// If we have an error while reading the file defined by the user. // If we have an error while reading the file defined by the user.
Err(err) if opts.config_file_path.is_some() => anyhow::bail!(err), Err(_) if opts.config_file_path.is_some() => anyhow::bail!(
"unable to open or read the {:?} configuration file.",
opts.config_file_path.unwrap().display().to_string()
),
_ => (), _ => (),
} }
} }