man icon indicating copy to clipboard operation
man copied to clipboard

Have method for file path

Open yoshuawuyts opened this issue 7 years ago • 3 comments

Applies to #10. Per https://github.com/killercup/clap-man-demo/blob/master/build.rs#L17-L19, we should have a method to generate a file name.

API

Current

for man in gen_manuals(&app) {
    let name = "clap-man-demo.1"; // FIXME: Extract this from man!
    let path = PathBuf::from(&outdir).join(name);
    let mut out = fs::File::create(&path).unwrap();
    out.write_all(man.render().as_bytes()).unwrap();
}

Proposed

for man in gen_manuals(&app) {
    let path = PathBuf::from(env!("CARGO_PKG_NAME")).push(man.path());
    fs::write(path, man.render())?;
}

yoshuawuyts avatar Aug 06 '18 08:08 yoshuawuyts

Alternative proposal

Introduce render_to which accepts a W: Writer directly instead of allocating a string internally.

for man in gen_manuals(&app) {
    let path = PathBuf::from(env!("CARGO_PKG_NAME")).push(man.path());
    man.render_to(fs::File::create(&path)?)?;
}

This is more work and it will only be really useful if we manage to add a similar API to our roff crate (not that hard), too; rroff already works like this internally.

killercup avatar Aug 06 '18 08:08 killercup

@killercup oh I like that a lot! - I reckon if we go with your approach, we should also introduce a method to at least have access to the name. E.g. so if people choose to go with a deviating approach (for whatever reason) at least the basic requirements are available to them.

yoshuawuyts avatar Aug 06 '18 11:08 yoshuawuyts

Perhaps we could make this a good first issue to help onboard someone?

yoshuawuyts avatar Aug 06 '18 11:08 yoshuawuyts