summaryrefslogtreecommitdiffstats
path: root/vendor/xflags/examples/hello-generated.rs
blob: cb74acbd746d0d8a911d56f37455669434f00509 (plain)
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
43
44
45
46
47
48
49
mod flags {
    #![allow(unused)]

    xflags::xflags! {
        src "./examples/hello-generated.rs"

        /// Prints a greeting.
        cmd hello {
            /// Whom to greet.
            required name: String

            /// Use non-ascii symbols in the output.
            optional -e, --emoji
        }
    }

    // generated start
    // The following code is generated by `xflags` macro.
    // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
    #[derive(Debug)]
    pub struct Hello {
        pub name: String,

        pub emoji: bool,
    }

    impl Hello {
        #[allow(dead_code)]
        pub fn from_env() -> xflags::Result<Self> {
            Self::from_env_()
        }

        #[allow(dead_code)]
        pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
            Self::from_vec_(args)
        }
    }
    // generated end
}

fn main() {
    match flags::Hello::from_env() {
        Ok(flags) => {
            let bang = if flags.emoji { "❣️" } else { "!" };
            println!("Hello {}{}", flags.name, bang);
        }
        Err(err) => err.exit(),
    }
}