mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
feat: skip usage errors
This commit is contained in:
parent
8429ce2872
commit
ab3534f0ef
1 changed files with 16 additions and 10 deletions
|
|
@ -60,18 +60,24 @@ pub fn suggest_command(shell: &str, last_command: &str, error_msg: &str) -> Opti
|
||||||
{
|
{
|
||||||
use crate::requests::ai_suggestion;
|
use crate::requests::ai_suggestion;
|
||||||
use textwrap::{fill, termwidth};
|
use textwrap::{fill, termwidth};
|
||||||
let suggest = ai_suggestion(last_command, error_msg);
|
|
||||||
if let Some(suggest) = suggest {
|
|
||||||
let warn = format!("{}:", t!("ai-suggestion")).bold().blue();
|
|
||||||
let note = fill(&suggest.note, termwidth());
|
|
||||||
|
|
||||||
eprintln!("{}\n{}\n", warn, note);
|
// skip for commands with no arguments,
|
||||||
let command = suggest.command;
|
// very likely to be an error showing the usage
|
||||||
if command != "None" {
|
if PRIVILEGE_LIST.contains(&split_command[0].as_str()) && split_command.len() > 2
|
||||||
if PRIVILEGE_LIST.contains(&split_command[0].as_str()) {
|
|| !PRIVILEGE_LIST.contains(&split_command[0].as_str()) && split_command.len() > 1 {
|
||||||
return Some(format!("{} {}", split_command[0], command));
|
let suggest = ai_suggestion(last_command, error_msg);
|
||||||
|
if let Some(suggest) = suggest {
|
||||||
|
let warn = format!("{}:", t!("ai-suggestion")).bold().blue();
|
||||||
|
let note = fill(&suggest.note, termwidth());
|
||||||
|
|
||||||
|
eprintln!("{}\n{}\n", warn, note);
|
||||||
|
let command = suggest.command;
|
||||||
|
if command != "None" {
|
||||||
|
if PRIVILEGE_LIST.contains(&split_command[0].as_str()) {
|
||||||
|
return Some(format!("{} {}", split_command[0], command));
|
||||||
|
}
|
||||||
|
return Some(command);
|
||||||
}
|
}
|
||||||
return Some(command);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue