mirror of
https://github.com/dalance/procs.git
synced 2026-10-12 02:12:39 +00:00
Add --gen-man-page flag that renders a man page to stdout. Build-time generation is also supported via the MAN_PATH env var, mirroring the existing COMPLETION_PATH pattern.
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use clap::CommandFactory;
|
|
|
|
include!("src/opt.rs");
|
|
|
|
fn main() {
|
|
if let Ok(path) = std::env::var("COMPLETION_PATH") {
|
|
let out_dir = PathBuf::from(path);
|
|
|
|
gen_completion(Shell::Bash, &out_dir, &mut Opt::command()).unwrap();
|
|
gen_completion(Shell::Elvish, &out_dir, &mut Opt::command()).unwrap();
|
|
gen_completion(Shell::Fish, &out_dir, &mut Opt::command()).unwrap();
|
|
gen_completion(Shell::PowerShell, &out_dir, &mut Opt::command()).unwrap();
|
|
gen_completion(Shell::Zsh, &out_dir, &mut Opt::command()).unwrap();
|
|
}
|
|
|
|
// MAN_PATH=./man cargo build
|
|
if let Ok(path) = std::env::var("MAN_PATH") {
|
|
let out_dir = std::path::Path::new(&path);
|
|
std::fs::create_dir_all(out_dir).unwrap();
|
|
let cmd = Opt::command();
|
|
let man = clap_mangen::Man::new(cmd);
|
|
let mut buf = Vec::new();
|
|
man.render(&mut buf).unwrap();
|
|
std::fs::write(out_dir.join("procs.1"), buf).unwrap();
|
|
println!(
|
|
"man page is generated: {}",
|
|
out_dir.join("procs.1").display()
|
|
);
|
|
}
|
|
}
|