-
Notifications
You must be signed in to change notification settings - Fork 87
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
Expose HelpMessage and allow for custom help switches #53
base: master
Are you sure you want to change the base?
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 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that, it looks good to me. Could you rebase, and make sure you format with cargo fmt
?
@@ -268,6 +268,7 @@ pub struct TypeAttrs { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -207,6 +207,17 @@ impl<T: SubCommand> SubCommands for T { | |||
const COMMANDS: &'static [&'static CommandInfo] = &[T::COMMAND]; | |||
} | |||
|
|||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why an additional trait instead of adding a method to FromArgs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help message only exists for struct
s, not for enum
s, so it's not implemented for every type that implements FromArgs
This pull request introduces a
HelpMessage
trait 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-h
or-?
and similar customizations. Closes #30