Skip to content

Conversation

@msrd0
Copy link

@msrd0 msrd0 commented Sep 5, 2020

This pull request introduces a HelpMessage trait that is implemented for every struct that derives FromArgs, allowing the user to manually display the help message generated by argh. 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

@google-cla
Copy link

google-cla bot commented Sep 5, 2020

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@msrd0
Copy link
Author

msrd0 commented Sep 5, 2020

@googlebot I signed it!

@jyn514
Copy link

jyn514 commented Oct 7, 2020

I would be very interested in having this for https://github.com/poliorcetics/cargo-intraconv :)

Copy link
Collaborator

@erickt erickt left a 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?

pub is_subcommand: Option<syn::Ident>,
pub name: Option<syn::LitStr>,
pub description: Option<Description>,
pub disable_help: Option<syn::LitBool>,
Copy link
Collaborator

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 { ... }.

Copy link
Author

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


/// A `HelpMessage` implementation that provides a help/usage message corresponding
/// to the type's `FromArgs` implementation.
pub trait HelpMessage: FromArgs {
Copy link
Collaborator

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?

Copy link
Author

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 structs, not for enums, so it's not implemented for every type that implements FromArgs

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.

Offer ability to short circuit help output (Ex: -h)

3 participants