conf.rs: accept default action "Y" when asking to create config

Reported by: bronsen
memfd
Manos Pitsidianakis 2020-07-10 15:55:15 +03:00
parent d914f7afd9
commit edfd2b1fef
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 7 additions and 3 deletions

View File

@ -312,9 +312,13 @@ impl FileSettings {
pub fn new() -> Result<FileSettings> {
let config_path = get_config_file()?;
if !config_path.exists() {
let path_string = config_path.display().to_string();
if path_string.is_empty() {
return Err(MeliError::new("No configuration found."));
}
println!(
"No configuration found. Would you like to generate one in {}? [Y/n]",
config_path.display()
path_string
);
let mut buffer = String::new();
let stdin = io::stdin();
@ -327,7 +331,7 @@ impl FileSettings {
.expect("Could not read from stdin.");
match buffer.trim() {
"Y" | "y" | "yes" | "YES" | "Yes" => {
"" | "Y" | "y" | "yes" | "YES" | "Yes" => {
create_config_file(&config_path)?;
return Err(MeliError::new(
"Edit the sample configuration and relaunch meli.",
@ -339,7 +343,7 @@ impl FileSettings {
_ => {
println!(
"No configuration found. Would you like to generate one in {}? [Y/n]",
config_path.display()
path_string
);
}
}