mod alias; mod cd; mod exit; mod export; mod source; use crate::compose::Environment; use crate::poem::Verse; /// A static list of all the built-in commands static INDEX: [&str; 7] = [ "alias", "cd", "exit", "export", "source", "unalias", "unset", ]; /// 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 { "alias" => alias::incant(verse, &mut env.aliases), "cd" => cd::incant(verse), "exit" => exit::incant(), "export" => export::incant(verse), "source" => source::incant(verse, env), "unalias" => alias::unincant(verse, &mut env.aliases), "unset" => export::unincant(verse), _ => unreachable!(), } }