diff options
author | Rory Dudley | 2024-06-14 20:29:32 -0400 |
---|---|---|
committer | Rory Dudley | 2024-06-14 20:29:32 -0400 |
commit | fedd4c31b0d1c6d036b1105a74b6e6a1f135f2b4 (patch) | |
tree | 3dc44055f9a452c8bbeb7e6ab1e45b65ebbb7417 /src/poem/anthology | |
parent | c4cd1e2c165c4f34ebf67fa9350f8732b2aeca13 (diff) | |
download | dwarvish-fedd4c31b0d1c6d036b1105a74b6e6a1f135f2b4.tar.gz |
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.
Diffstat (limited to 'src/poem/anthology')
-rw-r--r-- | src/poem/anthology/which.rs | 29 |
1 files changed, 16 insertions, 13 deletions
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<Vec<String>>, 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 { |