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 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();
|
|
||||||
|
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)?;
|
man.render(&mut buffer)?;
|
||||||
|
|
||||||
std::fs::write(
|
let mut out_path = out_dir.clone();
|
||||||
cli.out_file.unwrap_or_else(|| "./target/git-identity.1".into()),
|
out_path.push(man.get_filename());
|
||||||
buffer,
|
|
||||||
)?;
|
std::fs::write(out_path, buffer)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
render("git-identity", cli::Cli::command())?;
|
||||||
|
render("git-identity-import", cli::ImportCli::command())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue