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