clap/examples/tutorial_builder/03_01_flag_count.rs
Ed Page 31b22d1a51 perf(parser): Take up less memory with ArgAction::Count
Someone should not reasonably expect a coun flag to go up to billions,
millions, or even thousands.  255 should be sufficient for anyone,
right?

The original type was selected to be consistent with
`ArgMatches::occurrences_of` but that is also used for tracking how
many values appear which can be large with `xargs`.

I'm still conflicted on what the "right type" is an wish we could
support any numeric type.  When I did a search on github though, every
case was for debug/quiet flags and only supported 2-3 occurrences,
making a `u8` overkill.

This came out of a discussion on #3792
2022-06-09 11:09:38 -05:00

16 lines
355 B
Rust

// Note: this requires the `cargo` feature
use clap::{arg, command, ArgAction};
fn main() {
let matches = command!()
.arg(arg!(-v - -verbose).action(ArgAction::Count))
.get_matches();
println!(
"verbose: {:?}",
matches
.get_one::<u8>("verbose")
.expect("Count always defaulted")
);
}