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/recite.rs | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'src/poem/recite.rs') diff --git a/src/poem/recite.rs b/src/poem/recite.rs index b33cc87..b27ef75 100644 --- a/src/poem/recite.rs +++ b/src/poem/recite.rs @@ -1,5 +1,6 @@ use super::Poem; use crate::compose::Environment; +use crate::path; use crate::poem::anthology; use crate::poem::elements::rune::Rune; use crate::poem::elements::stanza::Stanza; @@ -141,36 +142,28 @@ impl Reciteable for Poem { None => {} }; + // Check if the verse's verb exists + let mut spell = None; + if !verse.verb().is_empty() { + // Check if the verb exists on the PATH + // If it doesn't exist, try refreshing the binary cache, and check again + // If it still doesn't exist, print an error + spell = verse.spellcheck(&env.bins); + if !spell.is_some() { + env.bins = path::refresh(); + spell = verse.spellcheck(&env.bins); + if !spell.is_some() { + eprintln!("dwvsh: {}: command not found", verse.verb()); + + if verse.meter != Rune::And { + continue; + } + } + } + } + // Incant the verse if it's a built-in - let status = - verse.incant(&mut out, &mut pids, env, anthology::lookup(&verse.verb()))?; - // let status = if index.is_some() { - // anthology::incant(&verse, &mut out, index.unwrap(), env) - // } else { - // // Checking for environment variables and running internal - // // poems may mean that the verb is empty now, so check it once - // // more - // // If it is empty, just continue to the next verse - // if !verse.verb().is_empty() { - // // Check if the verb exists on the PATH - // // If it doesn't exist, try refreshing the binary cache, and check - // // again - // // If it still doesn't exist, print an error - // if !verse.spellcheck(&env.bins).is_some() { - // env.bins = path::refresh(); - // if !verse.spellcheck(&env.bins).is_some() { - // eprintln!("dwvsh: {}: command not found", verse.verb()); - // - // if verse.meter != Rune::And { - // continue; - // } - // } - // } - // } else { - // continue; - // } - // verse.incant(&mut out, &mut pids, anthology::lookup(&verse.verb()))? - // }; + let status = verse.incant(&mut out, &mut pids, env, spell)?; // Break from the loop if the meter is not [Rune::Continue], and // if the status is not 0 -- cgit v1.2.3