#parser #parse #arg #gflags #argments

zflags

my common rust code

3 releases

0.1.2 Nov 16, 2021
0.1.1 Nov 16, 2021
0.1.0 Nov 16, 2021

#72 in #arg

MIT license

10KB
232 lines

zflags

A gflags style implementation based clap

Example:
#[macro_use]
extern crate zflags;

static V1: zflags::optv = option!(None, "x", "exec", None, 8, None);
static V2: zflags::optv = option!("fi", "x", "exec", None, None, "help");
static V3: zflags::optv = option!("s2", "x", "exec", "file", "ls", None);

mod sub {
    static V: zflags::optv = option!(None, "d", None, "day", "1970-1-1", "default date");
    pub fn print() {
        let date = V.str().unwrap();
        println!("date {}", date);
    }
}

fn main() {
    option_parse!("clap", "v0.1.0");
    let s1: i32 = V1.parse().unwrap();
    println!("{}", s1);

    match V2.parse::<String>() {
        Ok(n) => println!("fi -x {}", n),
        Err(s) => println!("{}", s),
    }

    match V3.str() {
        Ok(n) => println!("s2 -x {}", n),
        Err(s) => println!("{}", s),
    }
}

output:

zylthinking@linux:~/code/flags/tests$ ./clap -h
clap v0.1.0

USAGE:
    clap [OPTIONS] [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -x, --exec <unspecified>     [default: 8]
    -d <day>                    default date [default: "1970-1-1"]

SUBCOMMANDS:
    fi      
    help    Prints this message or the help of the given subcommand(s)
    s2

zylthinking@linux:~/code/flags/tests$ ./clap -d 2021-11-16 s2 -x bash
8
not in subcommand context
s2 -x bash
date 2021-11-16

Dependencies

~4.5MB
~78K SLoC