2023-07-31 14:27:44 +02:00
|
|
|
use colored::Colorize;
|
2023-08-07 16:25:43 +02:00
|
|
|
use crate::style::highlight_difference;
|
2023-07-31 14:27:44 +02:00
|
|
|
|
2023-07-31 14:12:45 +02:00
|
|
|
mod args;
|
2023-08-03 21:26:41 +02:00
|
|
|
mod files;
|
2023-07-30 18:40:18 +02:00
|
|
|
mod shell;
|
|
|
|
|
mod style;
|
2023-08-01 20:29:02 +02:00
|
|
|
mod suggestions;
|
2023-07-30 18:40:18 +02:00
|
|
|
|
|
|
|
|
fn main() {
|
2023-07-31 14:12:45 +02:00
|
|
|
args::handle_args();
|
2023-07-30 18:40:18 +02:00
|
|
|
|
2023-07-31 14:12:45 +02:00
|
|
|
let shell = std::env::var("_PR_SHELL").expect(
|
|
|
|
|
"No _PR_SHELL in environment. Did you aliased the binary with the correct arguments?",
|
|
|
|
|
);
|
|
|
|
|
let last_command = shell::last_command_expanded_alias(&shell);
|
2023-08-01 20:29:02 +02:00
|
|
|
let corrected_command = suggestions::suggest_command(&shell, &last_command);
|
2023-07-31 01:58:37 +02:00
|
|
|
|
2023-07-31 09:24:46 +02:00
|
|
|
if let Some(corrected_command) = corrected_command {
|
2023-08-07 16:25:43 +02:00
|
|
|
let command_difference = highlight_difference(&shell, &corrected_command, &last_command);
|
|
|
|
|
if let Some(command) = command_difference {
|
|
|
|
|
suggestions::confirm_suggestion(&shell, &command);
|
2023-07-31 23:42:19 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|
2023-07-31 23:42:19 +02:00
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
"No correction found for the command: {}\n",
|
2023-08-01 20:29:02 +02:00
|
|
|
last_command.red()
|
2023-07-31 23:42:19 +02:00
|
|
|
);
|
2023-07-31 23:48:14 +02:00
|
|
|
println!(
|
|
|
|
|
"If you think there should be a correction, please open an issue or send a pull request!"
|
|
|
|
|
);
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|