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")
|
2020-06-20 10:52:39 +00:00
|
|
|
.license("MIT OR Apache-2.0")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("0.1")
|
|
|
|
.author("Kevin K.")
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("input")
|
2020-04-21 15:51:38 +00:00
|
|
|
.about("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 check if a subcommand was used like normal
|
|
|
|
if matches.is_present("add") {
|
|
|
|
println!("'myapp add' was run.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// You can get the independent subcommand matches (which function exactly like App matches)
|
|
|
|
if let Some(ref matches) = matches.subcommand_matches("add") {
|
|
|
|
// 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"),
|
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...
|
|
|
|
}
|