|
| 1 | +use clap::CommandFactory; |
| 2 | +use clap_mangen::Man; |
| 3 | +use clap_mangen::roff::{Roff, roman}; |
| 4 | +use std::env; |
| 5 | +use std::fs; |
| 6 | + |
| 7 | +include!("src/cli.rs"); |
| 8 | + |
| 9 | +fn main() -> std::io::Result<()> { |
| 10 | + // Use OUT_DIR for build artifacts, not source directory |
| 11 | + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 12 | + |
| 13 | + let cmd = Args::command(); |
| 14 | + let man = Man::new(cmd); |
| 15 | + |
| 16 | + let mut buffer: Vec<u8> = Default::default(); |
| 17 | + |
| 18 | + // Render standard sections |
| 19 | + man.render_title(&mut buffer)?; |
| 20 | + man.render_name_section(&mut buffer)?; |
| 21 | + man.render_synopsis_section(&mut buffer)?; |
| 22 | + man.render_description_section(&mut buffer)?; |
| 23 | + man.render_options_section(&mut buffer)?; |
| 24 | + |
| 25 | + // Add custom EXAMPLES section |
| 26 | + let mut roff = Roff::default(); |
| 27 | + roff.control("SH", ["EXAMPLES"]); |
| 28 | + roff.text([roman("Basic usage (stdin/stdout):")]); |
| 29 | + roff.text([roman(" bmap2simg file.bmap < input.img > output.simg")]); |
| 30 | + roff.text([roman("")]); |
| 31 | + roff.text([roman("With input file flag:")]); |
| 32 | + roff.text([roman(" bmap2simg file.bmap -i input.img > output.simg")]); |
| 33 | + roff.text([roman("")]); |
| 34 | + roff.text([roman("With output file flag:")]); |
| 35 | + roff.text([roman(" bmap2simg file.bmap -o output.simg < input.img")]); |
| 36 | + roff.text([roman("")]); |
| 37 | + roff.text([roman("With both flags:")]); |
| 38 | + roff.text([roman(" bmap2simg file.bmap -i input.img -o output.simg")]); |
| 39 | + roff.text([roman("")]); |
| 40 | + roff.text([roman("Pipeline with XZ compression:")]); |
| 41 | + roff.text([roman(" xzcat 2025-10-01-raspios-trixie-arm64.img.xz \\")]); |
| 42 | + roff.text([roman( |
| 43 | + " | bmap2simg 2025-10-01-raspios-trixie-arm64.bmap \\", |
| 44 | + )]); |
| 45 | + roff.text([roman(" | xz -6 \\")]); |
| 46 | + roff.text([roman(" > 2025-10-01-raspios-trixie-arm64.simg.xz")]); |
| 47 | + roff.text([roman("")]); |
| 48 | + roff.text([roman("This example demonstrates efficient processing of compressed images: decompress the XZ-compressed")]); |
| 49 | + roff.text([roman("image on-the-fly, convert it to sparse format using the block map, then recompress the sparse")]); |
| 50 | + roff.text([roman("image. This avoids storing the full uncompressed image on disk while creating a compressed")]); |
| 51 | + roff.text([roman( |
| 52 | + "sparse image that preserves the original block structure.", |
| 53 | + )]); |
| 54 | + |
| 55 | + roff.to_writer(&mut buffer)?; |
| 56 | + |
| 57 | + fs::write(out_dir.join("bmap2simg.1"), buffer)?; |
| 58 | + |
| 59 | + println!("cargo:rerun-if-changed=src/cli.rs"); |
| 60 | + println!("cargo:rerun-if-changed=src/main.rs"); |
| 61 | + |
| 62 | + Ok(()) |
| 63 | +} |
0 commit comments