easy_flag

Crates.ioeasy_flag
lib.rseasy_flag
version0.1.2
sourcesrc
created_at2019-11-17 20:20:56.755173
updated_at2019-11-20 17:08:19.180204
descriptionSimple command line flag parser
homepagehttps://crates.io/crates/easy_flag
repositoryhttps://github.com/billyfbrain/easy_flag
max_upload_size
id182064
size27,644
BillyfBrain (billyfbrain)

documentation

https://docs.rs/easy_flag/0.1.0/easy_flag/

README

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

Licensed under either of Apache License, Version2.0 or MIT license at your option.
Commit count: 6

cargo fmt