mirror of
https://github.com/Noratrieb/badargs.git
synced 2026-01-15 12:15:06 +01:00
making optionality a bool
This commit is contained in:
parent
346c8835cd
commit
a33b81c58e
5 changed files with 47 additions and 34 deletions
|
|
@ -1,12 +1,20 @@
|
|||
#[macro_export]
|
||||
macro_rules! arg {
|
||||
// implicit optional
|
||||
($name:ident: $long:literal, $short:literal -> $result:ty) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::Some($short)) -> $result);
|
||||
arg!(@$name: ($long, ::std::option::Option::Some($short)) -> $result, false);
|
||||
};
|
||||
($name:ident: $long:literal -> $result:ty) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::None) -> $result);
|
||||
arg!(@$name: ($long, ::std::option::Option::None) -> $result, false);
|
||||
};
|
||||
(@$name:ident: ($long:literal, $short:expr) -> $result:ty) => {
|
||||
// required
|
||||
($name:ident: $long:literal, $short:literal -> $result:ty, required) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::Some($short)) -> $result, true);
|
||||
};
|
||||
($name:ident: $long:literal -> $result:ty, required) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::None) -> $result, true);
|
||||
};
|
||||
(@$name:ident: ($long:literal, $short:expr) -> $result:ty, $required:literal) => {
|
||||
#[derive(Default)]
|
||||
struct $name;
|
||||
|
||||
|
|
@ -20,6 +28,10 @@ macro_rules! arg {
|
|||
fn short() -> Option<char> {
|
||||
$short
|
||||
}
|
||||
|
||||
fn required() -> bool {
|
||||
$required
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue