Open mr-briggs opened 2 days ago
Note that changing things after a build
is undefined from the APIs perspective. This isn't directly called out in #2911 but is related to that.
What we need is a way for users to get the built-in help
behavior when they provide their own help. Help flags started by us auto-detecting a help flag being present (without us being told it shouldn't exist) and then keying off of that. We then switched to the ArgAction system so you could attach a Help action to any flag. Huh, I thought I had done some exploring on this idea but can only find #3773 which alludes to commands not being supported but thats it.
This could also be helpful for #1553.
Potentially related
Oh interesting, thank you for the insight about build
.
I had initially began this issue as "add help_about
and version_about
to Command
" but after some digging, found that they did actually briefly exist back when it was called App
. They were removed a few months later in favour of using mut_arg
to modify them after building the App
(see this comment), but I'm not sure how things have changed since then.
What we need is a way for users to get the built-in
help
behavior when they provide their own help.
Huh, that's probably more understandable for users, rather than modifying an auto-gen'd command that they might not even know about. One downside of specifying your own help
command though is that it becomes a possible match
arm (at least when deriving Subcommand
on an enum
) even though it's not a valid option under most circumstances (assuming the user-defined help
would have the same behaviour of returning Err(ErrorKind::DisplayHelp ...)
.
That's possibly not a major concern though, compared to the upside of being able to customize the help
message.
Please complete the following tasks
Clap Version
4.5.20
Describe your use case
It's currently fairly cumbersome to alter the
about
message for auto-generated help subcommands when usingclap-derive
. Consider the following example scenario:To use the parser as-is, we can run something like:
But if we'd like to customize the
about
message for the generated help subcommand, we can no longer use the niceparse
methods onCli
, and instead need to do something like:And for the sake of completeness, if we now run this with
cargo run -- help
, we'd get:Describe the solution you'd like
One way to streamline this would be to provide a
build()
method onCommand
which returnsself
, so that we can directly callmut_subcommand
in the#[command()]
macro. For example, ifCommand
had something like:Then we could do the following:
Note that trying to use
build()
in place of thebuild_for_derive()
above doesn't work, asbuild()
mutates theCommand
in-place and doesn't return anything, which breaks theParser
derive macro.Alternatives, if applicable
No response
Additional Context
No response