flatten/
flatten.rs

1//! All the flags don't have to live in the same structure, this example uses non derive version.
2//! with derive API you would use `external` annotation
3
4use bpaf::*;
5
6#[allow(dead_code)]
7#[derive(Debug, Clone)]
8struct Cmdline {
9    /// switch verbosity on
10    verbose: bool,
11    daemon_opts: DaemonOpts,
12}
13
14#[allow(dead_code)]
15#[derive(Debug, Clone)]
16struct DaemonOpts {
17    /// daemon user
18    user: String,
19
20    /// daemon group
21    group: String,
22}
23
24fn main() {
25    let verbose = short('v').help("switch verbosity on").switch();
26    let user = short('u').help("daemon user").argument::<String>("USER");
27    let group = short('g').help("daemon group").argument::<String>("GROUP");
28    let daemon_opts = construct!(DaemonOpts { user, group });
29    let opt = construct!(Cmdline {
30        verbose,
31        daemon_opts
32    })
33    .to_options()
34    .run();
35    println!("{:?}", opt);
36}