oh shit this might actually be quite usable

This commit is contained in:
nora 2021-09-24 22:17:30 +02:00
parent c126dda2df
commit cdb67f070c
5 changed files with 221 additions and 48 deletions

25
src/macros.rs Normal file
View 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
}
}
};
}