mirror of
https://github.com/clap-rs/clap
synced 2024-11-11 07:14:15 +00:00
docs(examples): Use correct arg keys
This commit is contained in:
parent
7c24e937f8
commit
cdc5026410
3 changed files with 6 additions and 6 deletions
|
@ -31,7 +31,7 @@ fn main() {
|
|||
//
|
||||
// Using other methods such as unwrap_or_else(|e| println!("{}",e))
|
||||
// are possible too.
|
||||
let len: u32 = matches.value_of_t("len").unwrap_or(10);
|
||||
let len: u32 = matches.value_of_t("l").unwrap_or(10);
|
||||
|
||||
println!("len ({}) + 2 = {}", len, len + 2);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ fn main() {
|
|||
let mut patch = 3;
|
||||
|
||||
// See if --set-ver was used to set the version manually
|
||||
let version = if let Some(ver) = matches.value_of("ver") {
|
||||
let version = if let Some(ver) = matches.value_of("set-ver") {
|
||||
ver.to_string()
|
||||
} else {
|
||||
// Increment the one requested (in a real program, we'd reset the lower numbers)
|
||||
|
@ -80,7 +80,7 @@ fn main() {
|
|||
if matches.is_present("config") {
|
||||
let input = matches
|
||||
.value_of("INPUT_FILE")
|
||||
.unwrap_or_else(|| matches.value_of("SPEC_IN").unwrap());
|
||||
.unwrap_or_else(|| matches.value_of("spec-in").unwrap());
|
||||
println!(
|
||||
"Doing work using input {} and config {}",
|
||||
input,
|
||||
|
|
|
@ -18,19 +18,19 @@ fn main() {
|
|||
.get_matches();
|
||||
|
||||
// You can check if a subcommand was used like normal
|
||||
if matches.is_present("add") {
|
||||
if matches.is_present("ls") {
|
||||
println!("'myapp add' was run.");
|
||||
}
|
||||
|
||||
// You can get the independent subcommand matches (which function exactly like App matches)
|
||||
if let Some(matches) = matches.subcommand_matches("add") {
|
||||
if let Some(matches) = matches.subcommand_matches("ls") {
|
||||
// Safe to use unwrap() because of the required() option
|
||||
println!("Adding file: {}", matches.value_of("input").unwrap());
|
||||
}
|
||||
|
||||
// You can also match on a subcommand's name
|
||||
match matches.subcommand_name() {
|
||||
Some("add") => println!("'myapp add' was used"),
|
||||
Some("ls") => println!("'myapp add' was used"),
|
||||
None => println!("No subcommand was used"),
|
||||
_ => println!("Some other subcommand was used"),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue