Skip to main content

zig_core/
docs.rs

1/// Embedded documentation pages, compiled from `docs/` markdown files.
2///
3/// Docs cover concepts (the `.zwf`/`.zwfz` format, patterns, variables, …) as
4/// opposed to command references, which live under `zig man`.
5mod 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    pub const DRY_RUN: &str = include_str!("../docs/dry-run.md");
13}
14
15/// All available docs topics in display order.
16pub const TOPICS: &[(&str, &str)] = &[
17    ("zwf", "The .zwf/.zwfz workflow format"),
18    ("patterns", "Orchestration patterns"),
19    ("variables", "Variable system and data flow"),
20    ("conditions", "Condition expressions"),
21    ("memory", "Memory scratch pad and the `<memory>` block"),
22    (
23        "storage",
24        "Workflow storage — structured writable working data",
25    ),
26    ("dry-run", "Preview a workflow run without invoking zag"),
27];
28
29/// Look up a docs page by topic name.
30///
31/// Returns the markdown content if the topic exists, or `None`.
32pub fn get(topic: &str) -> Option<&'static str> {
33    match topic {
34        "zwf" => Some(pages::ZWF),
35        "patterns" => Some(pages::PATTERNS),
36        "variables" => Some(pages::VARIABLES),
37        "conditions" => Some(pages::CONDITIONS),
38        "memory" => Some(pages::MEMORY),
39        "storage" => Some(pages::STORAGE),
40        "dry-run" => Some(pages::DRY_RUN),
41        _ => None,
42    }
43}
44
45/// List all available docs topics with their descriptions.
46pub fn list_topics() -> String {
47    let mut out = String::from("Available docs:\n\n");
48    let max_name_len = TOPICS.iter().map(|(name, _)| name.len()).max().unwrap_or(0);
49    for (name, description) in TOPICS {
50        out.push_str(&format!(
51            "  {name:<width$}  {description}\n",
52            width = max_name_len
53        ));
54    }
55    out.push_str("\nUsage: zig docs <topic>");
56    out
57}
58
59#[cfg(test)]
60#[path = "docs_tests.rs"]
61mod tests;