diff --git a/src/main.rs b/src/main.rs index ee86cc1..6ee9e60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,35 +48,39 @@ fn main() { let mut last_command = shell::last_command_expanded_alias(&shell); let mut error_msg = command_output(&shell, &last_command); loop { - let corrected_command = suggestions::suggest_command(&shell, &last_command, &error_msg); - - if let Some(corrected_command) = corrected_command { - let command_difference = - highlight_difference(&shell, &corrected_command, &last_command); - if let Some(highlighted_command) = command_difference { - let execution = suggestions::confirm_suggestion( - &shell, - &corrected_command, - &highlighted_command, - ); - if execution.is_ok() { - return; - } else { - last_command = corrected_command; - error_msg = execution.err().unwrap(); - - let retry_message = format!("{}...", t!("retry")); - - // println!("\n{} {}", "ERROR:".red().bold(), msg); - eprintln!("\n{}\n", retry_message.cyan().bold()); - } - } else { + let suggestion = { + let command = suggestions::suggest_command(&shell, &last_command, &error_msg); + if command.is_none() { break; - } + }; + command.unwrap() + }; + + let highlighted_suggestion = { + let deffirence = highlight_difference(&shell, &suggestion, &last_command); + if deffirence.is_none() { + break; + }; + deffirence.unwrap() + }; + + let execution = + suggestions::confirm_suggestion(&shell, &suggestion, &highlighted_suggestion); + if execution.is_ok() { + return; } else { - break; + last_command = suggestion; + error_msg = execution.err().unwrap(); + + let retry_message = format!("{}...", t!("retry")); + + eprintln!("\n{}\n", retry_message.cyan().bold()); } } eprintln!("{}: {}\n", t!("no-suggestion"), last_command.red()); - eprintln!("{}\n{}", t!("contribute"), "https://github.com/iffse/pay-respects"); + eprintln!( + "{}\n{}", + t!("contribute"), + "https://github.com/iffse/pay-respects" + ); } diff --git a/src/shell.rs b/src/shell.rs index 29520fc..99bd82b 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -29,7 +29,7 @@ pub fn command_output(shell: &str, command: &str) -> String { Ok(output) => match output.stderr.is_empty() { true => String::from_utf8_lossy(&output.stdout).to_lowercase(), false => String::from_utf8_lossy(&output.stderr).to_lowercase(), - } + }, Err(_) => { use colored::*; eprintln!("Timeout while executing command: {}", command.red());