-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic.rs
More file actions
35 lines (33 loc) · 900 Bytes
/
basic.rs
File metadata and controls
35 lines (33 loc) · 900 Bytes
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
use args::{
Argument,
ArgumentParser,
ArgumentType,
ArgumentValue,
};
fn main() {
let parser = ArgumentParser::new("basic")
.with_description("Basic parse() example with required/optional args")
.with_author("lambda team")
.with_argument(
Argument::new("--name")
.is_required(true)
.with_type(ArgumentType::String),
)
.with_argument(
Argument::new("--count")
.with_type(ArgumentType::Integer)
.with_default_value(ArgumentValue::Integer(1)),
);
let args: Vec<String> = std::env::args().collect();
match parser.parse(&args) {
Ok(parsed) => {
let name = parsed.get_string("--name").unwrap();
let count = parsed.get_i64("--count").unwrap();
println!("name={}, count={}", name, count);
}
Err(e) => {
// HelpRequested prints usage text via Display
eprintln!("{}", e);
}
}
}