3 releases

0.1.2 Nov 20, 2019
0.1.1 Nov 20, 2019
0.1.0 Nov 17, 2019

#594 in Command-line interface

Download history 8/week @ 2024-08-09 5/week @ 2024-08-16 6/week @ 2024-08-23 13/week @ 2024-08-30 20/week @ 2024-09-06 6/week @ 2024-09-13 19/week @ 2024-09-20 12/week @ 2024-09-27 18/week @ 2024-10-04 12/week @ 2024-10-11 21/week @ 2024-10-18 31/week @ 2024-10-25 24/week @ 2024-11-01

94 downloads per month

MIT/Apache

16KB
313 lines

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.

lib.rs:

easy_flag is a simple command line flag parser.

This library contains functions for handling command line flags.

Example

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(())
}

No runtime deps