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 std::path::PathBuf;
use clap::{CommandFactory as _, Parser}; use clap::{CommandFactory as _, Parser};
use git_identity::cli;
/// Render the manpage of git-identity from its clap definition /// Render the manpage of git-identity from its clap definition
#[derive(Parser)] #[derive(Parser)]
pub struct Cli { 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" /// By default, this is "./target"
out_file: Option<PathBuf>, out_dir: Option<PathBuf>,
} }
pub fn main(cli: Cli) -> anyhow::Result<()> { pub fn main(cli: Cli) -> anyhow::Result<()> {
let man = clap_mangen::Man::new(git_identity::cli::Cli::command()); let out_dir = cli.out_dir.unwrap_or_else(|| PathBuf::from("./target"));
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write( let render = |name: &'static str, command: clap::Command| -> anyhow::Result<()> {
cli.out_file.unwrap_or_else(|| "./target/git-identity.1".into()), let man = clap_mangen::Man::new(command.name(name));
buffer,
)?; let mut buffer = Vec::<u8>::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(()) Ok(())
} }