clap/tests/global_args.rs
Kevin K 4cc85990fd
refactor: removed strings as an internal ID for arguments, groups, and
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.
2019-04-05 20:21:22 -04:00

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"]);
}
}