diff --git a/xtask/src/manpage.rs b/xtask/src/manpage.rs index daaa9df..cf4e4f3 100644 --- a/xtask/src/manpage.rs +++ b/xtask/src/manpage.rs @@ -1,25 +1,36 @@ use std::path::PathBuf; use clap::{CommandFactory as _, Parser}; +use git_identity::cli; /// Render the manpage of git-identity from its clap definition #[derive(Parser)] pub struct Cli { - /// The file in which to write the newly generated manpage + /// The directory in which to write the newly generated manpages /// - /// By default, this is "target/git-identity.1" - out_file: Option, + /// By default, this is "./target" + out_dir: Option, } pub fn main(cli: Cli) -> anyhow::Result<()> { - let man = clap_mangen::Man::new(git_identity::cli::Cli::command()); - let mut buffer: Vec = Default::default(); - man.render(&mut buffer)?; + let out_dir = cli.out_dir.unwrap_or_else(|| PathBuf::from("./target")); - std::fs::write( - cli.out_file.unwrap_or_else(|| "./target/git-identity.1".into()), - buffer, - )?; + let render = |name: &'static str, command: clap::Command| -> anyhow::Result<()> { + let man = clap_mangen::Man::new(command.name(name)); + + let mut buffer = Vec::::new(); + man.render(&mut buffer)?; + + let mut out_path = out_dir.clone(); + out_path.push(man.get_filename()); + + std::fs::write(out_path, buffer)?; + + Ok(()) + }; + + render("git-identity", cli::Cli::command())?; + render("git-identity-import", cli::ImportCli::command())?; Ok(()) }