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
Allow defining help heading for help flags #4831
Comments
The simplest way to create a custom help flag is to add |
For context, clap v2 had various API settings for customizing the built-in help. At least by clap v3, we had
These created a system that "just worked" in some cases but then completely failed in others without a clear reason. These were also slow at runtime and bloated the binary. From this, we decided to use the |
I did try that (amongst other things) before making this GitHub issue but tripped on the necessary associated type. I initially assumed it should be a I think additional documentation here, perhaps in the ArgAction documentation or in the derive tutorial may help ensure others don't trip on the same issue I did. That said, I recognize it's a delicate balance; making a tutorial too long may inhibit people's desire to consume its entirety. Many thanks both for your help here and your work on clap in general. [0] A minimal example:
resulted in:
The solution here appears to be to set the type to
resulted in the expected behavior:
|
Not working with |
Please complete the following tasks
Clap Version
4.2
Describe your use case
My derive-based application has
#[clap(global = true)]
flags placed under#[clap(help_heading = "Common options")]
and per-subcommand flags placed under per-subcommandhelp_heading
s. The-h
/--help
flag should be placed under#[clap(help_heading = "Common options")]
, as it is available irrelevant of subcommand, but there is no straight forward way to define a heading for this flag other than the defaultOptions
.Describe the solution you'd like
Something like a
#[clap(help_flag_help_heading = "..."]
setting available via clap's derive API to define the help flag'shelp_heading
.Alternatives, if applicable
#[clap(disable_help_flag = true)]
paired with a way to manually add-h
/--help
via the derive API. This would in turn require:::parse()
does not exit with the'<executable>' requires subcommand but one was not provided
message when-h
/--help
is provided rather than a subcommand.print_help()
via the derive API, both for the application as a whole and per-subcommand. I could only find ways to do this via the builder API.Additional Context
A very similar situation arises with the version flag. While I do not use it, others who do may benefit from it being taken into consideration here as well, e.g. by adding a
#[clap(version_flag_help_heading = "...")]
or making aprint_version()
accessible via the derive API.The text was updated successfully, but these errors were encountered: