1use qargparser as arg;
2
3#[derive(Default, Debug)]
4struct MyContext {
5 do_help: bool
6}
7
8fn help_proc(
9 _spec: &arg::Spec<MyContext>,
10 ctx: &mut MyContext,
11 _args: &Vec<String>
12) {
13 ctx.do_help = true;
14}
15
16
17fn main() -> Result<(), Box<dyn std::error::Error>> {
18 let help_spec = arg::Builder::new()
19 .sopt('h')
20 .lopt("help")
21 .exit(true)
22 .help(&["Show this help."])
23 .build(help_proc);
24 let coll_spec = arg::Builder::new()
25 .sopt('h')
26 .lopt("hulp")
27 .exit(true)
28 .help(&["Show this help."])
29 .build(help_proc);
30
31
32 let ctx = MyContext {
33 ..Default::default()
34 };
35 let mut prsr = arg::Parser::from_env(ctx);
36
37 prsr.add(help_spec)?;
38 prsr.add(coll_spec)?;
39
40 prsr.parse()?;
41
42 if prsr.get_ctx().do_help == true {
44 prsr.usage(&mut std::io::stdout());
45 std::process::exit(0);
46 }
47
48 println!("{:?}", prsr.get_ctx());
49
50 Ok(())
51}
52
53
54