16 releases

0.4.0-pre.1 Apr 29, 2024
0.3.2 Dec 18, 2023
0.3.1 Oct 22, 2022
0.2.4 Mar 2, 2022
0.1.4 Mar 5, 2021

#1927 in Procedural macros

Download history 8258/week @ 2024-01-25 8758/week @ 2024-02-01 10279/week @ 2024-02-08 10994/week @ 2024-02-15 9112/week @ 2024-02-22 8944/week @ 2024-02-29 9395/week @ 2024-03-07 9516/week @ 2024-03-14 10083/week @ 2024-03-21 9545/week @ 2024-03-28 8689/week @ 2024-04-04 9534/week @ 2024-04-11 9532/week @ 2024-04-18 9083/week @ 2024-04-25 8356/week @ 2024-05-02 6510/week @ 2024-05-09

34,895 downloads per month
Used in 21 crates (via xflags)

MIT/Apache

37KB
1K SLoC

API reference

xflags

Moderately simple command line arguments parsing:

mod flags {
    use std::path::PathBuf;

    xflags::xflags! {
        src "./examples/basic.rs"

        cmd my-command {
            required path: PathBuf
            optional -v, --verbose
        }
    }

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

        pub verbose: bool,
    }

    impl MyCommand {
        pub const HELP: &'static str = Self::HELP_;

        pub fn from_env() -> xflags::Result<Self> {
            Self::from_env_()
        }

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

fn main() {
    let flags = flags::MyCommand::from_env();
    println!("{:#?}", flags);
}

No runtime deps