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
Shell completions include --version
on subcommands despite no version set
#2860
Labels
Milestone
Comments
epage
added
C-bug
Category: Updating dependencies
A-completion
Area: completion generator
labels
Oct 12, 2021
Oof, I forgot about tracking this issue. The context is: We do lazy building of the subcommand to improve performance in our parser once we match a subcommand. But generators need all the subcommands to be built. I have a |
Thanks for the pointer! |
epage
added a commit
to epage/clap
that referenced
this issue
Oct 12, 2021
`App::get_matches` lazily post-processes `App`s and `Arg`s so we don't do it to subcommands that are never run (downside being people have to exercise their full app to get debug_asserts). `clap_generate` was only post-processing the top-level `App` and `Arg`s, ignoring the sub-commands. In clap-rs#2858, we noticed that `--version` was being left in the completions instead of being removed during the `_build` step. We would also have an incorrect `num_vals` and a host of other problems. This change adds a `App::_build_all` function for `clap_generate` to use to eagerly build everything. By having it there, we make sure everywhere that needs eager building, gets it (like some tests). In `clap_generate::utils`, we add a unit test to ensure the subcommand's `--version` was removed. For some other tests specifying `.version()`, I added `AppSettings::PropagateVersion` to make it behave more consistently. The places I didn't were generally where the version was conditionally set. For `clap_generate/tests/generate_completions.rs`, I had to adjust the `conflicts_with` because the subcommand was inheriting the argument with it defined *but* the subcommand did not have the argument, tripping up a debug assert. Fixes clap-rs#2860
epage
added a commit
to epage/clap
that referenced
this issue
Oct 12, 2021
`App::get_matches` lazily post-processes `App`s and `Arg`s so we don't do it to subcommands that are never run (downside being people have to exercise their full app to get debug_asserts). `clap_generate` was only post-processing the top-level `App` and `Arg`s, ignoring the sub-commands. In clap-rs#2858, we noticed that `--version` was being left in the completions instead of being removed during the `_build` step. We would also have an incorrect `num_vals` and a host of other problems. This change adds a `App::_build_all` function for `clap_generate` to use to eagerly build everything. By having it there, we make sure everywhere that needs eager building, gets it (like some tests). In `clap_generate::utils`, we add a unit test to ensure the subcommand's `--version` was removed. For some other tests specifying `.version()`, I added `AppSettings::PropagateVersion` to make it behave more consistently. The places I didn't were generally where the version was conditionally set. For `clap_generate/tests/generate_completions.rs`, I had to adjust the `conflicts_with` because the subcommand was inheriting the argument with it defined *but* the subcommand did not have the argument, tripping up a debug assert. Fixes clap-rs#2860
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please complete the following tasks
Rust Version
rustc 1.55.0 (c8dfcfe04 2021-09-06)
Clap Version
master
Minimal reproducible code
This snippet is using the API the generators used, so it can demonstrate the problem
Steps to reproduce the bug with the above code
Run it
Actual Behaviour
See a
version
flag included for each subcommandExpected Behaviour
No output should happen
Additional Context
This was found as part of #2858.
If I'm reading this correctly, #2831 relied on
fn _build
to remove--version
in the call to_check_help_and_version
but we don't recursively call_build
on subcommands, leaving the auto-generated flag behind.if this is the case, then probably a lot of subcommand behavior is broken because we'd never call
_build
on their args.Debug Output
Note the single logged
App::_build
, rather than one-per-subcommand.The text was updated successfully, but these errors were encountered: