2018-11-14 17:05:06 +00:00
|
|
|
use clap::{App, Arg};
|
2016-05-11 18:14:17 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let matches = App::new("MyApp")
|
2018-01-25 04:05:05 +00:00
|
|
|
.subcommand(
|
2018-10-19 20:42:13 +00:00
|
|
|
App::new("ls")
|
2018-01-25 04:05:05 +00:00
|
|
|
.aliases(&["list", "dir"])
|
|
|
|
.about("Adds files to myapp")
|
|
|
|
.version("0.1")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("input")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the file to add")
|
2018-01-25 04:05:05 +00:00
|
|
|
.index(1)
|
|
|
|
.required(true),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.get_matches();
|
2016-05-11 18:14:17 +00:00
|
|
|
|
|
|
|
// You can also match on a subcommand's name
|
2021-11-12 14:17:51 +00:00
|
|
|
match matches.subcommand() {
|
|
|
|
Some(("ls", sub_matches)) => println!(
|
|
|
|
"'myapp add' was used, input is: {}",
|
2021-11-12 14:42:25 +00:00
|
|
|
sub_matches
|
|
|
|
.value_of("input")
|
|
|
|
.expect("'input' is required and parsing will fail if its missing")
|
2021-11-12 14:17:51 +00:00
|
|
|
),
|
2018-01-25 04:05:05 +00:00
|
|
|
None => println!("No subcommand was used"),
|
|
|
|
_ => println!("Some other subcommand was used"),
|
2016-05-11 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Continued program logic goes here...
|
|
|
|
}
|