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

#2190 in Procedural macros

Download history 8967/week @ 2024-07-30 9189/week @ 2024-08-06 8414/week @ 2024-08-13 9094/week @ 2024-08-20 8912/week @ 2024-08-27 8454/week @ 2024-09-03 7711/week @ 2024-09-10 7805/week @ 2024-09-17 8843/week @ 2024-09-24 7653/week @ 2024-10-01 8050/week @ 2024-10-08 8133/week @ 2024-10-15 8095/week @ 2024-10-22 8313/week @ 2024-10-29 8948/week @ 2024-11-05 9304/week @ 2024-11-12

36,108 downloads per month
Used in 23 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