easy_flag 0.1.2

Simple command line flag parser
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented4 out of 8 items with examples
  • Size
  • Source code size: 27.27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.55 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • billyfbrain/easy_flag
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • billyfbrain

easy_flag

Simple command line flag parser for rust.

use easy_flag::FlagSet;

fn main() -> Result<(), String>{
    let mut help = false;
    let mut my_flag = String::from("default value");
    let args: Vec<String> = std::env::args().collect();

    let mut my_set = FlagSet::new(&args[0])
        .add("-h, --help", &mut help, "Prints help message.")
        .add("-m, --my-flag", &mut my_flag, "Help message for my_flag with string `value`");

    if let Err(err) = my_set.parse(&args[1..]) {
        println!("{}", my_set.defaults());
        return Err(err);
    }

    let usage = my_set.usage();
    if help {
        println!("{}", usage);
        return Ok(());
    }

    println!("my_flag flag value: {}", my_flag);

    Ok(())
}

License