mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
fc359e3c46
The example code. ~~~rust use clap::{App, Arg}; fn main() { let matches = App::new("My Super Program") .arg( Arg::with_name("verbose") .help("Sets the level of verbosity") .short('v') .long("verbose") .takes_value(false) .multiple_occurrences(true) .env("VERBOSE"), ) .get_matches(); match matches.occurrences_of("verbose") { 0 => println!("0 No verbose info"), 1 => println!("1 Some verbose info"), 2 => println!("2 Tons of verbose info"), 3 | _ => println!("3 >= Don't be crazy"), } } ~~~ It code use multiple_occurrences with env. But it do not work. `env` method set require take value. It result see under. ~~~console % cargo run -- -v Finished dev [unoptimized + debuginfo] target(s) in 0.01s Running `target/debug/foo -v` error: The argument '--verbose <verbose>...' requires a value but none was supplied USAGE: foo [OPTIONS] For more information try --help ~~~ And, structopt or clap_derive may be create similar code. So I am confused by structopt. This to fix code small. |
||
---|---|---|
.. | ||
app.yml | ||
app_2space.yml | ||
app_settings.rs | ||
arg_aliases.rs | ||
borrowed.rs | ||
conflicts.rs | ||
default_vals.rs | ||
delimiters.rs | ||
derive_order.rs | ||
env.rs | ||
example1_tmpl_full.txt | ||
example1_tmpl_simple.txt | ||
flags.rs | ||
global_args.rs | ||
groups.rs | ||
help.rs | ||
hidden_args.rs | ||
indices.rs | ||
macros.rs | ||
multiple_occurrences.rs | ||
multiple_values.rs | ||
opts.rs | ||
positionals.rs | ||
posix_compatible.rs | ||
possible_values.rs | ||
propagate_globals.rs | ||
require.rs | ||
subcommands.rs | ||
template_help.rs | ||
tests.rs | ||
unique_args.rs | ||
utf8.rs | ||
version-numbers.rs | ||
version.rs | ||
yaml.rs |