fix: modules

This commit is contained in:
iff 2024-12-08 15:33:43 +01:00
parent 5aebf867c1
commit fedee1dc8d
12 changed files with 54 additions and 39 deletions

View file

@ -1,16 +1,25 @@
mod replaces;
mod rules;
fn main() -> Result<(), std::io::Error>{
let executable = std::env::var("_PR_COMMAND").unwrap();
let shell = std::env::var("_PR_SHELL").unwrap();
let last_command = std::env::var("_PR_LAST_COMMAND").unwrap();
let error_msg = std::env::var("_PR_ERROR_MSG").unwrap();
fn main() -> Result<(), std::io::Error> {
let executable = std::env::var("_PR_COMMAND").expect("_PR_COMMAND not set");
let shell = std::env::var("_PR_SHELL").expect("_PR_SHELL not set");
let last_command = std::env::var("_PR_LAST_COMMAND").expect("_PR_LAST_COMMAND not set");
let error_msg = std::env::var("_PR_ERROR_MSG").expect("_PR_ERROR_MSG not set");
let executables: Vec<String> = {
let executables = std::env::var("_PR_EXECUTABLES").unwrap();
let executables = std::env::var("_PR_EXECUTABLES").expect("_PR_EXECUTABLES not set");
executables.split(",").map(|s| s.to_string()).collect()
};
#[cfg(debug_assertions)]
{
eprintln!("shell: {}", shell);
eprintln!("executable: {}", executable);
eprintln!("last_command: {}", last_command);
eprintln!("error_msg: {}", error_msg);
eprintln!("executables: {:?}", executables);
}
rules::runtime_match(&executable, &shell, &last_command, &error_msg, &executables);
Ok(())
}

View file

@ -183,4 +183,3 @@ pub fn shell(suggest: &mut String, shell: &str) {
suggest.replace_range(placeholder, &command.join("\n"));
}
}

View file

@ -13,7 +13,7 @@ struct MatchError {
}
pub fn runtime_match(
executable: &str,
executable: &str,
shell: &str,
last_command: &str,
error_msg: &str,
@ -83,16 +83,11 @@ pub fn runtime_match(
if pure_suggest.contains("{{command}}") {
pure_suggest = pure_suggest.replace("{{command}}", last_command);
}
print!("{}",
eval_suggest(
&pure_suggest,
last_command,
error_msg,
executables,
shell,
)
print!(
"{}",
eval_suggest(&pure_suggest, last_command, error_msg, executables, shell,)
);
print!("{}", "<_PR_BR>");
print!("<_PR_BR>");
}
}
}
@ -194,4 +189,3 @@ fn get_rule(executable: &str) -> Option<String> {
None
}