pub mod cd; pub mod exit; pub mod export; pub mod source; use crate::compose::Environment; use crate::poem::Verse; /// A static list of all the built-in commands static INDEX: [&str; 4] = ["cd", "exit", "export", "source"]; /// Lookup the index of a built-in command /// /// Looks up the index of a built-in command in [INDEX], accounting for aliases pub fn lookup(verb: &str) -> Option { let verb = match verb { "quit" => "exit", // Alias 'quit' to 'exit' "set" => "export", // Alias 'set' to 'export' _ => verb, }; INDEX.iter().position(|v| v.to_string() == verb) } pub fn incant(verse: &Verse, index: usize, env: &mut Environment) -> i32 { let verb = INDEX[index]; match verb { "cd" => cd::incant(verse), "exit" => exit::incant(), "export" => export::incant(verse), "source" => source::incant(verse, env), _ => unreachable!(), } }