generate all the man pages in the manpage xtask
This commit is contained in:
parent
76fe594896
commit
e85ac6a5e5
1 changed files with 21 additions and 10 deletions
|
|
@ -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();
|
||||
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::<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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue