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}
11
12/// All available manpage topics in display order.
13pub const TOPICS: &[(&str, &str)] = &[
14    ("zig", "Overview of the zig CLI"),
15    ("run", "Execute a .zwf/.zwfz workflow file"),
16    ("listen", "Tail a running or completed zig session"),
17    ("serve", "Start an HTTP API server"),
18    (
19        "workflow",
20        "Manage workflows (list, show, create, update, delete, pack)",
21    ),
22    ("validate", "Validate a .zwf or .zwfz workflow file"),
23    (
24        "resources",
25        "Manage reference files advertised to step agents",
26    ),
27];
28
29/// Look up a manpage 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        "zig" => Some(pages::ZIG),
35        "run" => Some(pages::RUN),
36        "listen" => Some(pages::LISTEN),
37        "serve" => Some(pages::SERVE),
38        "workflow" => Some(pages::WORKFLOW),
39        "validate" => Some(pages::VALIDATE),
40        "resources" => Some(pages::RESOURCES),
41        _ => None,
42    }
43}
44
45/// List all available manpage topics with their descriptions.
46pub fn list_topics() -> String {
47    let mut out = String::from("Available manpages:\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 man <topic>");
56    out
57}
58
59#[cfg(test)]
60#[path = "man_tests.rs"]
61mod tests;