mirror of
https://github.com/Noratrieb/badargs.git
synced 2026-01-15 04:05:07 +01:00
oh shit this might actually be quite usable
This commit is contained in:
parent
c126dda2df
commit
cdb67f070c
5 changed files with 221 additions and 48 deletions
25
src/macros.rs
Normal file
25
src/macros.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#[macro_export]
|
||||
macro_rules! arg {
|
||||
($name:ident: $long:literal, $short:literal -> $result:ty) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::Some($short)) -> $result);
|
||||
};
|
||||
($name:ident: $long:literal -> $result:ty) => {
|
||||
arg!(@$name: ($long, ::std::option::Option::None) -> $result);
|
||||
};
|
||||
(@$name:ident: ($long:literal, $short:expr) -> $result:ty) => {
|
||||
#[derive(Default)]
|
||||
struct $name;
|
||||
|
||||
impl ::badargs::CliArg for $name {
|
||||
type Content = $result;
|
||||
|
||||
fn long() -> &'static str {
|
||||
$long
|
||||
}
|
||||
|
||||
fn short() -> Option<&'static str> {
|
||||
$short
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue