17 releases

0.4.0-pre.2 Oct 31, 2024
0.4.0-pre.1 Apr 29, 2024
0.3.2 Dec 18, 2023
0.3.1 Oct 22, 2022
0.2.1 Mar 6, 2021

#2370 in Procedural macros

Download history 8091/week @ 2024-10-27 8893/week @ 2024-11-03 9211/week @ 2024-11-10 9858/week @ 2024-11-17 8477/week @ 2024-11-24 9667/week @ 2024-12-01 10339/week @ 2024-12-08 9875/week @ 2024-12-15 6661/week @ 2024-12-22 7432/week @ 2024-12-29 9599/week @ 2025-01-05 9976/week @ 2025-01-12 10228/week @ 2025-01-19 10481/week @ 2025-01-26 11248/week @ 2025-02-02 10769/week @ 2025-02-09

43,786 downloads per month
Used in 24 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