1mod 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 DESCRIBE: &str = include_str!("../manpages/describe.md");
9 pub const VALIDATE: &str = include_str!("../manpages/validate.md");
10 pub const ZUG: &str = include_str!("../manpages/zug.md");
11 pub const PATTERNS: &str = include_str!("../manpages/patterns.md");
12 pub const VARIABLES: &str = include_str!("../manpages/variables.md");
13 pub const CONDITIONS: &str = include_str!("../manpages/conditions.md");
14}
15
16pub const TOPICS: &[(&str, &str)] = &[
18 ("zig", "Overview of the zig CLI"),
19 ("run", "Execute a .zug workflow file"),
20 ("listen", "Tail a running or completed zig session"),
21 ("serve", "Start an HTTP API server"),
22 (
23 "workflow",
24 "Manage workflows (list, show, create, delete, pack)",
25 ),
26 ("describe", "Generate a .zug file from a prompt"),
27 ("validate", "Validate a .zug workflow file"),
28 ("zug", "The .zug workflow format"),
29 ("patterns", "Orchestration patterns"),
30 ("variables", "Variable system and data flow"),
31 ("conditions", "Condition expressions"),
32];
33
34pub fn get(topic: &str) -> Option<&'static str> {
38 match topic {
39 "zig" => Some(pages::ZIG),
40 "run" => Some(pages::RUN),
41 "listen" => Some(pages::LISTEN),
42 "serve" => Some(pages::SERVE),
43 "workflow" => Some(pages::WORKFLOW),
44 "describe" => Some(pages::DESCRIBE),
45 "validate" => Some(pages::VALIDATE),
46 "zug" => Some(pages::ZUG),
47 "patterns" => Some(pages::PATTERNS),
48 "variables" => Some(pages::VARIABLES),
49 "conditions" => Some(pages::CONDITIONS),
50 _ => None,
51 }
52}
53
54pub fn list_topics() -> String {
56 let mut out = String::from("Available manpages:\n\n");
57 let max_name_len = TOPICS.iter().map(|(name, _)| name.len()).max().unwrap_or(0);
58 for (name, description) in TOPICS {
59 out.push_str(&format!(
60 " {name:<width$} {description}\n",
61 width = max_name_len
62 ));
63 }
64 out.push_str("\nUsage: zig man <topic>");
65 out
66}
67
68#[cfg(test)]
69#[path = "man_tests.rs"]
70mod tests;