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}
12
13/// All available docs topics in display order.
14pub 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
22/// Look up a docs page by topic name.
23///
24/// Returns the markdown content if the topic exists, or `None`.
25pub 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
36/// List all available docs topics with their descriptions.
37pub 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;