mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
bfa02fd418
This ports our example testing over to [trycmd](https://docs.rs/) so we can: - More thoroughly test our examples - Provide always-up-to-date example usage The old way of testing automatically picked up examples. This new way requires we have a `.md` file that uses the example in some way. Notes: - Moved overall example description to the `.md` file - I added cross-linking between related examples - `14_groups` had a redundant paragraph (twice talked about "one and only one"
30 lines
965 B
Rust
30 lines
965 B
Rust
use clap::{App, Arg};
|
|
|
|
fn main() {
|
|
let matches = App::new("myapp")
|
|
.about("does awesome things")
|
|
.arg(
|
|
Arg::new("INPUT")
|
|
.help("The input file to use")
|
|
.default_value("input.txt")
|
|
.index(1),
|
|
)
|
|
// Next we'll use the Option::unwrap_or method on this "CONFIG" option
|
|
.arg(
|
|
Arg::new("CONFIG")
|
|
.help("The config file to use")
|
|
.short('c')
|
|
.takes_value(true),
|
|
)
|
|
.get_matches();
|
|
|
|
let input = matches
|
|
.value_of("INPUT")
|
|
.expect("'INPUT' is default and parsing will ensure there always is a value");
|
|
|
|
// Using Option::unwrap_or we get the same effect, but without the added help text injection
|
|
let config_file = matches.value_of("CONFIG").unwrap_or("config.json");
|
|
|
|
println!("The input file is: {}", input);
|
|
println!("The config file is: {}", config_file);
|
|
}
|