Skip to main content

zig_core/
man.rs

1/// Embedded manpage content, compiled from `manpages/` markdown files.
2mod pages {
3    pub const ZIG: &str = include_str!("../manpages/zig.md");
4    pub const RUN: &str = include_str!("../manpages/run.md");
5    pub const LISTEN: &str = include_str!("../manpages/listen.md");
6    pub const SERVE: &str = include_str!("../manpages/serve.md");
7    pub const WORKFLOW: &str = include_str!("../manpages/workflow.md");
8    pub const VALIDATE: &str = include_str!("../manpages/validate.md");
9    pub const RESOURCES: &str = include_str!("../manpages/resources.md");
10    pub const MEMORY: &str = include_str!("../manpages/memory.md");
11    pub const SELF: &str = include_str!("../manpages/self.md");
12}
13
14/// All available manpage topics in display order.
15pub const TOPICS: &[(&str, &str)] = &[
16    ("zig", "Overview of the zig CLI"),
17    ("run", "Execute a .zwf/.zwfz workflow file"),
18    ("listen", "Tail a running or completed zig session"),
19    ("serve", "Start an HTTP API server"),
20    (
21        "workflow",
22        "Manage workflows (list, show, create, update, delete, pack)",
23    ),
24    ("validate", "Validate a .zwf or .zwfz workflow file"),
25    (
26        "resources",
27        "Manage reference files advertised to step agents",
28    ),
29    (
30        "memory",
31        "Manage the memory scratch pad for workflows and steps",
32    ),
33    (
34        "self",
35        "Commands that act on the currently running zig/zag session",
36    ),
37];
38
39/// Look up a manpage by topic name.
40///
41/// Returns the markdown content if the topic exists, or `None`.
42pub fn get(topic: &str) -> Option<&'static str> {
43    match topic {
44        "zig" => Some(pages::ZIG),
45        "run" => Some(pages::RUN),
46        "listen" => Some(pages::LISTEN),
47        "serve" => Some(pages::SERVE),
48        "workflow" => Some(pages::WORKFLOW),
49        "validate" => Some(pages::VALIDATE),
50        "resources" => Some(pages::RESOURCES),
51        "memory" => Some(pages::MEMORY),
52        "self" => Some(pages::SELF),
53        _ => None,
54    }
55}
56
57/// List all available manpage topics with their descriptions.
58pub fn list_topics() -> String {
59    let mut out = String::from("Available manpages:\n\n");
60    let max_name_len = TOPICS.iter().map(|(name, _)| name.len()).max().unwrap_or(0);
61    for (name, description) in TOPICS {
62        out.push_str(&format!(
63            "  {name:<width$}  {description}\n",
64            width = max_name_len
65        ));
66    }
67    out.push_str("\nUsage: zig man <topic>");
68    out
69}
70
71#[cfg(test)]
72#[path = "man_tests.rs"]
73mod tests;