Crates.io | zflags |
lib.rs | zflags |
version | 0.1.2 |
source | src |
created_at | 2021-11-16 04:56:59.959095 |
updated_at | 2021-11-16 05:04:49.648926 |
description | my common rust code |
homepage | |
repository | |
max_upload_size | |
id | 482488 |
size | 9,907 |
A gflags style implementation based clap
#[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