hidden/
hidden.rs

1use qargparser as arg;
2
3#[derive(Default, Debug)]
4struct MyContext {
5  do_help: bool,
6  do_version: bool,
7  do_secret: bool
8}
9
10
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12  let help_spec = arg::Builder::new()
13    .sopt('h')
14    .lopt("help")
15    .exit(true)
16    .help(&["Show this help."])
17    .build(
18      |_spec: &arg::Spec<MyContext>,
19       ctx: &mut MyContext,
20       _args: &Vec<String>| ctx.do_help = true
21    );
22  let version_spec = arg::Builder::new()
23    .sopt('V')
24    .lopt("version")
25    .exit(true)
26    .help(&["Output tool version and exit."])
27    .build(
28      |_spec: &arg::Spec<MyContext>,
29       ctx: &mut MyContext,
30       _args: &Vec<String>| ctx.do_version = true
31    );
32  let secret_spec = arg::Builder::new()
33    .sopt('s')
34    .lopt("secret")
35    .hidden(true)
36    .help(&["A hidden option."])
37    .build(
38      |_spec: &arg::Spec<MyContext>,
39       ctx: &mut MyContext,
40       _args: &Vec<String>| ctx.do_secret = true
41    );
42
43
44  let ctx = MyContext {
45    ..Default::default()
46  };
47  let mut prsr = arg::Parser::from_env(ctx);
48
49  prsr.add(help_spec)?;
50  prsr.add(version_spec)?;
51  prsr.add(secret_spec)?;
52
53  prsr.parse()?;
54
55  if prsr.get_ctx().do_help == true {
56    prsr.usage(&mut std::io::stdout());
57    std::process::exit(0);
58  }
59
60  let ctx = prsr.into_ctx();
61
62  println!("{:?}", &ctx);
63
64  Ok(())
65}
66
67/* vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 : */