diff options
author | Rory Dudley | 2024-03-31 00:50:03 -0600 |
---|---|---|
committer | Rory Dudley | 2024-03-31 00:50:03 -0600 |
commit | 791b61f97e3ee12dfd765f5e23edd5df527eb803 (patch) | |
tree | beec5cfab87229b84897aa038b514e08d4532665 /src/poem/anthology.rs | |
parent | f03f4e0fcf62c9b3267bc5d8b62068d89ec593cd (diff) | |
download | dwarvish-791b61f97e3ee12dfd765f5e23edd5df527eb803.tar.gz |
Add docstring comments to all the anthology functions
Add docstring comments for all the incant function throughout the
anthology, documenting what each function does, and an example of it's
shell command.
Diffstat (limited to 'src/poem/anthology.rs')
-rw-r--r-- | src/poem/anthology.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/poem/anthology.rs b/src/poem/anthology.rs index 2a2f62a..9a0d2e4 100644 --- a/src/poem/anthology.rs +++ b/src/poem/anthology.rs @@ -13,7 +13,7 @@ static INDEX: [&str; 7] = [ /// Lookup the index of a built-in command /// -/// Looks up the index of a built-in command in [INDEX], accounting for aliases +/// Looks up the index of a built-in command in [INDEX], accounting for aliases. pub fn lookup(verb: &str) -> Option<usize> { let verb = match verb { "quit" => "exit", // Alias 'quit' to 'exit' @@ -23,6 +23,22 @@ pub fn lookup(verb: &str) -> Option<usize> { INDEX.iter().position(|v| v.to_string() == verb) } +/// Run a builtin command, based on its verb +/// +/// Use [lookup] to check if a verb is in the anthology's index (i.e. is a +/// builtin), then call this with the current verse, the index found by +/// [lookup], and the shell's global environment state. +/// +/// # Example +/// ``` +/// let index = anthology::lookup(verse.verb()); +/// if index.is_some() { +/// anthology::incant(&verse, index.unwrap(), env); +/// } else { +/// // Run an external command +/// ... +/// } +/// ``` pub fn incant(verse: &Verse, index: usize, env: &mut Environment) -> i32 { let verb = INDEX[index]; match verb { |