Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have method for file path #11

Open
yoshuawuyts opened this issue Aug 6, 2018 · 3 comments
Open

Have method for file path #11

yoshuawuyts opened this issue Aug 6, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@yoshuawuyts
Copy link
Collaborator

yoshuawuyts commented Aug 6, 2018

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())?;
}
@killercup
Copy link
Contributor

killercup commented Aug 6, 2018

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.

@yoshuawuyts
Copy link
Collaborator Author

@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 yoshuawuyts added the help wanted Extra attention is needed label Aug 6, 2018
@yoshuawuyts
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants