pay-respects/src/main.rs

35 lines
945 B
Rust
Raw Normal View History

2023-07-31 14:27:44 +02:00
use colored::Colorize;
use crate::style::highlight_difference;
2023-07-31 14:27:44 +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() {
args::handle_args();
2023-07-30 18:40:18 +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 {
let command_difference = highlight_difference(&shell, &corrected_command, &last_command);
2023-08-07 17:03:48 +02:00
if let Some(highlighted_command) = command_difference {
suggestions::confirm_suggestion(&shell, &corrected_command, &highlighted_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
}