use crate::compose::Environment; use crate::poem::Verse; pub fn incant(verse: &Verse, out: &mut Vec, env: &Environment) -> i32 { let mut status = 0; match verse.clause() { Some(clause) => { let mut output: String; for word in clause { // Check if it's an alias if env.aliases.contains_key(&word) { output = format!("{}: aliased to {}\n", word, env.aliases.get(&word).unwrap()); if verse.couplet > 0 { out.append(&mut output.as_bytes().to_vec()); } else { print!("{}", output); } continue; } // Check if it's a built-in match super::lookup(&word) { Some(_) => { output = format!("{}: shell built-in command\n", word); if verse.couplet > 0 { out.append(&mut output.as_bytes().to_vec()); } else { print!("{}", output); } continue; } None => {} } // Manually check the path let mut verb = Verse::new(); verb.push(word.clone()); match verb.spellcheck(&env.bins) { Some(i) => { output = format!("{}\n", env.bins[i]); if verse.couplet > 0 { out.append(&mut output.as_bytes().to_vec()); } else { print!("{}", output); } } None => { output = format!("{} not found\n", word); status = 1; eprint!("{}", output); } } } } None => { eprintln!("which: not enough arguments"); return 1; } } status }