mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 06:20:09 +01:00
refactor: split request-ai into module
This commit is contained in:
parent
fedee1dc8d
commit
c9b9f66f89
13 changed files with 151 additions and 106 deletions
36
pay-respects-fallback-request-ai/src/main.rs
Normal file
36
pay-respects-fallback-request-ai/src/main.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use crate::requests::ai_suggestion;
|
||||
use colored::Colorize;
|
||||
use textwrap::{fill, termwidth};
|
||||
mod requests;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rust_i18n;
|
||||
i18n!("i18n", fallback = "en", minify_key = true);
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let command = std::env::var("_PR_LAST_COMMAND").expect("_PR_LAST_COMMAND not set");
|
||||
let error = std::env::var("_PR_ERROR_MSG").expect("_PR_ERROR_MSG not set");
|
||||
colored::control::set_override(true);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
eprintln!("last_command: {}", command);
|
||||
eprintln!("error_msg: {}", error);
|
||||
}
|
||||
|
||||
// skip for commands with no arguments,
|
||||
// very likely to be an error showing the usage
|
||||
if command.split_whitespace().count() == 1 {
|
||||
return Ok(());
|
||||
}
|
||||
let suggest = ai_suggestion(&command, &error);
|
||||
if let Some(suggest) = suggest {
|
||||
let warn = format!("{}:", t!("ai-suggestion")).bold().blue();
|
||||
let note = fill(&suggest.note, termwidth());
|
||||
|
||||
eprintln!("{}\n{}", warn, note);
|
||||
let command = suggest.command;
|
||||
print!("{}<_PR_BR>", command);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue