Macro clap::clap_app [−][src]
Build App, Args, SubCommands and Groups with Usage-string like input
but without the associated parsing runtime cost.
clap_app! also supports several shorthand syntaxes.
Examples
let matches = clap_app!(myapp => (version: "1.0") (author: "Kevin K. <kbknapp@gmail.com>") (about: "Does awesome things") (@arg CONFIG: -c --config +takes_value "Sets a custom config file") (@arg INPUT: +required "Sets the input file to use") (@arg debug: -d ... "Sets the level of debugging information") (@group difficulty => (@arg hard: -h --hard "Sets hard mode") (@arg normal: -n --normal "Sets normal mode") (@arg easy: -e --easy "Sets easy mode") ) (@subcommand test => (about: "controls testing features") (version: "1.3") (author: "Someone E. <someone_else@other.com>") (@arg verbose: -v --verbose "Print test information verbosely") ) ) .get_matches();
Shorthand Syntax for Args
- A single hyphen followed by a character (such as -c) sets theArg::short
- A double hyphen followed by a character or word (such as --config) setsArg::long- If one wishes to use a Arg::longwith a hyphen inside (i.e.--config-file), you must use--("config-file")due to limitations of the Rust macro system.
 
- If one wishes to use a 
- Three dots (...) setsArg::multiple(true)
- Angled brackets after either a short or long will set Arg::value_nameandArg::required(true)such as--config <FILE>=Arg::value_name("FILE")andArg::required(true)
- Square brackets after either a short or long will set Arg::value_nameandArg::required(false)such as--config [FILE]=Arg::value_name("FILE")andArg::required(false)
- There are short hand syntaxes for Arg methods that accept booleans
- A plus sign will set that method to truesuch as+required=Arg::required(true)
- An exclamation will set that method to falsesuch as!required=Arg::required(false)
 
- A plus sign will set that method to 
- A #{min, max}will setArg::min_values(min)andArg::max_values(max)
- An asterisk (*) will setArg::required(true)
- Curly brackets around a fnwill setArg::validatoras in{fn}=Arg::validator(fn)
- An Arg method that accepts a string followed by square brackets will set that method such as
conflicts_with[FOO]will setArg::conflicts_with("FOO")(note the lack of quotes aroundFOOin the macro)
- An Arg method that takes a string and can be set multiple times (such as
Arg::conflicts_with) followed by square brackets and a list of values separated by spaces will set that method such asconflicts_with[FOO BAR BAZ]will setArg::conflicts_with("FOO"),Arg::conflicts_with("BAR"), andArg::conflicts_with("BAZ")(note the lack of quotes around the values in the macro)
Shorthand Syntax for Groups
- There are short hand syntaxes for ArgGroupmethods that accept booleans- A plus sign will set that method to truesuch as+required=ArgGroup::required(true)
- An exclamation will set that method to falsesuch as!required=ArgGroup::required(false)
 
- A plus sign will set that method to