generate all the man pages in the manpage xtask

This commit is contained in:
kalmenn 2026-02-02 13:01:16 +01:00
parent 76fe594896
commit e85ac6a5e5
Signed by: kalmenn
GPG key ID: F500055C44BC3834

View file

@ -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<PathBuf>,
/// By default, this is "./target"
out_dir: Option<PathBuf>,
}
pub fn main(cli: Cli) -> anyhow::Result<()> {
let man = clap_mangen::Man::new(git_identity::cli::Cli::command());
let mut buffer: Vec<u8> = Default::default();
let out_dir = cli.out_dir.unwrap_or_else(|| PathBuf::from("./target"));
let render = |name: &'static str, command: clap::Command| -> anyhow::Result<()> {
let man = clap_mangen::Man::new(command.name(name));
let mut buffer = Vec::<u8>::new();
man.render(&mut buffer)?;
std::fs::write(
cli.out_file.unwrap_or_else(|| "./target/git-identity.1".into()),
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(())
}