Expose HelpMessage and allow for custom help switches#53
Expose HelpMessage and allow for custom help switches#53msrd0 wants to merge 3 commits intogoogle:masterfrom msrd0:custom-help-flag
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
I would be very interested in having this for https://github.com/poliorcetics/cargo-intraconv :) |
erickt
left a comment
There was a problem hiding this comment.
Other than that, it looks good to me. Could you rebase, and make sure you format with cargo fmt?
| pub is_subcommand: Option<syn::Ident>, | ||
| pub name: Option<syn::LitStr>, | ||
| pub description: Option<Description>, | ||
| pub disable_help: Option<syn::LitBool>, |
There was a problem hiding this comment.
Stylistically, I think flipping this to "enable_help" reads a bit better. That avoids devs having to mentally parse expressions like if !disable_help { ... }.
There was a problem hiding this comment.
I chose disable_help because as a dev I usually assume optional boolean flags to default to false, but I can change that if you want
|
|
||
| /// A `HelpMessage` implementation that provides a help/usage message corresponding | ||
| /// to the type's `FromArgs` implementation. | ||
| pub trait HelpMessage: FromArgs { |
There was a problem hiding this comment.
Why an additional trait instead of adding a method to FromArgs?
There was a problem hiding this comment.
The help message only exists for structs, not for enums, so it's not implemented for every type that implements FromArgs
This pull request introduces a
HelpMessagetrait that is implemented for every struct that derivesFromArgs, allowing the user to manually display the help message generated byargh. Also, the user can specify#[argh(disable_help = true)]which disables the built-in help flag and allows the user to add custom help flags, allowing for shorthands like-hor-?and similar customizations. Closes #30