mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
a61b60816c
`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 #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 #2860
18 lines
500 B
Rust
18 lines
500 B
Rust
use clap::{App, Arg};
|
|
use clap_generate::generate;
|
|
use clap_generate_fig::Fig;
|
|
use std::io;
|
|
|
|
#[test]
|
|
fn generate_completions() {
|
|
let mut app = App::new("test_app")
|
|
.arg(Arg::new("config").short('c').global(true))
|
|
.arg(Arg::new("v").short('v').conflicts_with("config"))
|
|
.subcommand(
|
|
App::new("test")
|
|
.about("Subcommand")
|
|
.arg(Arg::new("debug").short('d')),
|
|
);
|
|
|
|
generate(Fig, &mut app, "test_app", &mut io::sink());
|
|
}
|