use std::fmt::Write as _;
use clap::Args;
use zad::error::{Result, ZadError};
#[derive(Debug, Args)]
pub struct ManArgs {
pub command: Option<String>,
}
pub const PAGES: &[(&str, &str)] = &[
("main", include_str!("../../man/main.md")),
("1pass", include_str!("../../man/1pass.md")),
("commands", include_str!("../../man/commands.md")),
("discord", include_str!("../../man/discord.md")),
("docs", include_str!("../../man/docs.md")),
("gcal", include_str!("../../man/gcal.md")),
("man", include_str!("../../man/man.md")),
("service", include_str!("../../man/service.md")),
("signing", include_str!("../../man/signing.md")),
("slack", include_str!("../../man/slack.md")),
("spotify", include_str!("../../man/spotify.md")),
("telegram", include_str!("../../man/telegram.md")),
("ymusic", include_str!("../../man/ymusic.md")),
];
pub fn run(args: ManArgs) -> Result<()> {
match args.command {
None => {
let mut out = String::new();
out.push_str("Available manpages (run `zad man <command>` to read):\n");
for (name, _) in PAGES {
let _ = writeln!(out, " {name}");
}
print!("{out}");
Ok(())
}
Some(command) => match PAGES.iter().find(|(n, _)| *n == command) {
Some((_, body)) => {
print!("{body}");
Ok(())
}
None => Err(ZadError::Invalid(format!(
"no manpage for: `{command}`. Run `zad man` to list available manpages."
))),
},
}
}