mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
4cc85990fd
subcommands This commit changes the internal ID to a u64 which will allow for greater optimizations down the road. In addition, it lays the ground work for allowing users to use things like enum variants as argument keys instead of strings. The only downside is each key needs to be hashed (the implementation used is an FNV hasher for performance). However, the performance gains in faster iteration, comparison, etc. should easily outweigh the single hash of each argument. Another benefit of if this commit is the removal of several lifetime parameters, as it stands Arg and App now only have a single lifetime parameter, and ArgMatches and ArgGroup have no lifetime parameter.
36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
extern crate clap;
|
|
extern crate regex;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
include!("../clap-test.rs");
|
|
use clap::{App, Arg};
|
|
|
|
fn get_app() -> App<'static> {
|
|
App::new("myprog")
|
|
.arg(
|
|
Arg::with_name("GLOBAL_ARG")
|
|
.long("global-arg")
|
|
.help("Specifies something needed by the subcommands")
|
|
.global(true)
|
|
.takes_value(true)
|
|
.default_value("default_value"),
|
|
)
|
|
.arg(
|
|
Arg::with_name("GLOBAL_FLAG")
|
|
.long("global-flag")
|
|
.help("Specifies something needed by the subcommands")
|
|
.multiple(true)
|
|
.global(true),
|
|
)
|
|
.subcommand(App::new("outer").subcommand(App::new("inner")))
|
|
}
|
|
|
|
#[test]
|
|
fn issue_1076() {
|
|
let mut app = get_app();
|
|
let _ = app.try_get_matches_from_mut(vec!["myprog"]);
|
|
let _ = app.try_get_matches_from_mut(vec!["myprog"]);
|
|
let _ = app.try_get_matches_from_mut(vec!["myprog"]);
|
|
}
|
|
}
|