mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
3be8bcf756
This better models what users should be doing and makes it so all comments are more clear. In a prior commit, when a changed an `exit` to `unwrap`, I disliked the fact that I was mixing an unwrap explanatory comment in with another comment. This makes them stand apart.
33 lines
1,010 B
Rust
33 lines
1,010 B
Rust
use clap::{App, Arg};
|
|
|
|
fn main() {
|
|
let matches = App::new("MyApp")
|
|
.subcommand(
|
|
App::new("ls")
|
|
.aliases(&["list", "dir"])
|
|
.about("Adds files to myapp")
|
|
.version("0.1")
|
|
.author("Kevin K.")
|
|
.arg(
|
|
Arg::new("input")
|
|
.about("the file to add")
|
|
.index(1)
|
|
.required(true),
|
|
),
|
|
)
|
|
.get_matches();
|
|
|
|
// You can also match on a subcommand's name
|
|
match matches.subcommand() {
|
|
Some(("ls", sub_matches)) => println!(
|
|
"'myapp add' was used, input is: {}",
|
|
sub_matches
|
|
.value_of("input")
|
|
.expect("'input' is required and parsing will fail if its missing")
|
|
),
|
|
None => println!("No subcommand was used"),
|
|
_ => println!("Some other subcommand was used"),
|
|
}
|
|
|
|
// Continued program logic goes here...
|
|
}
|