-
Notifications
You must be signed in to change notification settings - Fork 47
/
clap.rs
42 lines (38 loc) · 1.31 KB
/
clap.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern crate clap;
use clap::{Arg, App, SubCommand};
fn main() {
let app = App::new("My Super Program")
.version("1.0")
.author("Kevin K. <[email protected]>")
.about("Does awesome things")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true))
.arg(Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true)
.index(1))
.subcommand(SubCommand::with_name("test")
.about("controls testing features")
.arg(Arg::with_name("debug")
.short("d")
.help("print debug information verbosely")));
// Parse the command line arguments
let matches = app.get_matches();
let config = matches.value_of("config").unwrap_or("default.conf");
let input = matches.value_of("INPUT").unwrap();
// Handle subcommands
match matches.subcommand() {
("clone", Some(sub_matches)) => {
if matches.is_present("d") {
// ...
}
},
("push", Some(sub_matches)) => {},
("commit", Some(sub_matches)) => {},
_ => {},
}
}