1mod pages {
6 pub const ZWF: &str = include_str!("../docs/zwf.md");
7 pub const PATTERNS: &str = include_str!("../docs/patterns.md");
8 pub const VARIABLES: &str = include_str!("../docs/variables.md");
9 pub const CONDITIONS: &str = include_str!("../docs/conditions.md");
10 pub const MEMORY: &str = include_str!("../docs/memory.md");
11}
12
13pub const TOPICS: &[(&str, &str)] = &[
15 ("zwf", "The .zwf/.zwfz workflow format"),
16 ("patterns", "Orchestration patterns"),
17 ("variables", "Variable system and data flow"),
18 ("conditions", "Condition expressions"),
19 ("memory", "Memory scratch pad and the `<memory>` block"),
20];
21
22pub fn get(topic: &str) -> Option<&'static str> {
26 match topic {
27 "zwf" => Some(pages::ZWF),
28 "patterns" => Some(pages::PATTERNS),
29 "variables" => Some(pages::VARIABLES),
30 "conditions" => Some(pages::CONDITIONS),
31 "memory" => Some(pages::MEMORY),
32 _ => None,
33 }
34}
35
36pub fn list_topics() -> String {
38 let mut out = String::from("Available docs:\n\n");
39 let max_name_len = TOPICS.iter().map(|(name, _)| name.len()).max().unwrap_or(0);
40 for (name, description) in TOPICS {
41 out.push_str(&format!(
42 " {name:<width$} {description}\n",
43 width = max_name_len
44 ));
45 }
46 out.push_str("\nUsage: zig docs <topic>");
47 out
48}
49
50#[cfg(test)]
51#[path = "docs_tests.rs"]
52mod tests;