tools

various tools I have been using throughout the years
Log | Files | Refs | README | LICENSE

mangen.rs (703B)


      1 use std::io::Write;
      2 
      3 use clap::CommandFactory;
      4 
      5 fn main() -> std::io::Result<()> {
      6     let mut buffer = Vec::new();
      7     clap_mangen::Man::new(dam::Cli::command()).render(&mut buffer)?;
      8 
      9     match std::env::args().nth(1).or_else(default_out) {
     10         Some(path) => {
     11             std::fs::write(&path, buffer)?;
     12             eprintln!("generated {path}");
     13         }
     14         None => std::io::stdout().write_all(&buffer)?,
     15     }
     16     Ok(())
     17 }
     18 
     19 /// Default to dam.1 beside this crate's manifest when run through cargo;
     20 /// `option_env!` keeps it compiling under Bazel, where the path is passed in.
     21 fn default_out() -> Option<String> {
     22     option_env!("CARGO_MANIFEST_DIR").map(|dir| format!("{dir}/dam.1"))
     23 }