mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-13 15:00:15 +01:00
refactor: less nesting
This commit is contained in:
parent
76ac397890
commit
78c7d37b92
2 changed files with 31 additions and 27 deletions
56
src/main.rs
56
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"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue