From fedd4c31b0d1c6d036b1105a74b6e6a1f135f2b4 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Fri, 14 Jun 2024 20:29:32 -0400 Subject: Add back spellcheck This commit reworks spellcheck() so it is more verbose about what it returns. It also re-introduces the use of spellcheck() in Poem::recite(). Spellcheck now returns a value in the enum, Spelling: FullPath -> Indicates a full path was specified as the verb OnPath -> Indicates the verb is on the $PATH BuiltIn -> Indicates the verb is a built-in command None (Option) -> The verb does not exist This commit also removes some defunct (commented-out) code. --- src/poem/anthology/which.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/poem/anthology/which.rs') diff --git a/src/poem/anthology/which.rs b/src/poem/anthology/which.rs index 6fe709c..0872dda 100644 --- a/src/poem/anthology/which.rs +++ b/src/poem/anthology/which.rs @@ -1,4 +1,5 @@ use crate::compose::Environment; +use crate::poem::elements::verse::Spelling; use crate::poem::Verse; use std::os::unix::process::ExitStatusExt; use std::process::{ExitStatus, Output}; @@ -22,26 +23,28 @@ pub fn incant(clause: &Option>, uout: bool, uerr: bool, env: &Enviro continue; } - // Check if it's a built-in - match super::lookup(&word) { - Some(_) => { + // Manually check the path + let mut verb = Verse::new(); + verb.push(word.clone()); + match verb.spellcheck(&env.bins) { + Some(Spelling::OnPath(i)) => { + output = format!("{}\n", env.bins[i]); + if uout { + out.append(&mut output.as_bytes().to_vec()); + } else { + print!("{}", output); + } + } + Some(Spelling::BuiltIn(_)) => { output = format!("{}: shell built-in command\n", word); if uout { 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]); + Some(Spelling::FullPath) => { + output = format!("{}\n", word); if uout { out.append(&mut output.as_bytes().to_vec()); } else { -- cgit v1.2.3