Skip to content

Conversation

@arxanas
Copy link
Contributor

@arxanas arxanas commented Oct 11, 2021

No description provided.

Copy link
Member

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 11, 2021

Build succeeded:

@bors bors bot merged commit a63dcb3 into clap-rs:master Oct 11, 2021
@epage
Copy link
Member

epage commented Oct 11, 2021

@arxanas could you expand on what your use case is?

I can understand us having getters for everything, I'm just wanting to understand the workflow better for where someone needs get_long_about over something like write_long_help.

@pksunkara
Copy link
Member

I would use this in one of the generators I am planning.

@epage
Copy link
Member

epage commented Oct 11, 2021

@pksunkara could you share more? What is this generator? Why does it need this over write_long_help?

@arxanas arxanas deleted the get-long-help branch October 11, 2021 16:36
@arxanas
Copy link
Contributor Author

arxanas commented Oct 11, 2021

@epage The context is in arxanas/git-branchless#114, specifically at commit arxanas/git-branchless@3454ac9. The objective is to generate man-pages automatically. Actually, there is some documentation which says that clap v3 beta supports this: https://rust-cli.github.io/book/in-depth/docs.html, but I couldn't find the corresponding functionality. Maybe @pksunkara intends to implement it?

For the future reader, this is the workaround I used:

let mut buf = Vec::new();
command
    .clone()
    .help_template("{about}")
    .write_long_help(&mut buf)?;
let long_help = String::from_utf8(buf).expect("Argument help should be UTF-8");
manual = manual.description(long_help);

Notes on my development process:

  • The string needs to be preprocessed further to translate into a man page, so writing it to an intermediate buffer isn't helpful.
  • It's also not particularly helpful that it writes to std::io::Write instead of std::fmt::Write.
  • The write_long_help method was somewhat difficult to discover, as I was expecting a getter like the rest of the methods I was using.
  • write_long_help takes a &mut Self for some reason?
  • Furthermore, none of the print_help/write_help methods mention the help_template method, which controls the behavior of these methods. I only found that method by chance.

@epage
Copy link
Member

epage commented Oct 11, 2021

Thanks! That helps a lot and is a lot of great feedback!

btw you might find git-config-env of interest which I use in my somewhat-similar git-stack

Actually, there is some documentation which says that clap v3 beta supports this: https://rust-cli.github.io/book/in-depth/docs.html, but I couldn't find the corresponding functionality. Maybe @pksunkara intends to implement it?

I remember this coming up in a discussion on the book but I'm not finding it to see how we resolved it. I remember talk about this back when the book was being created but I missed what happened after that.

write_long_help takes a &mut Self for some reason?

Currently, we use this to generate and store some derived settings. Sometime after 3.0 I'd like to play with alternative ways of handling this.

@pksunkara
Copy link
Member

Yeah, I originally intended to have a basic manpage generator for 3.0. But I removed it from the milestone about an year ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants