summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arg_util.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/arg_util.rs b/src/arg_util.rs
index 8cd8fe5..c72d89b 100644
--- a/src/arg_util.rs
+++ b/src/arg_util.rs
@@ -24,12 +24,21 @@ macro_rules! count {
}
}
+/// Translate an optional source into an optional destination.
+macro_rules! tr {
+ ($dst:tt, $src:tt) => {
+ $dst
+ };
+ ($dst:tt) => {};
+}
+
macro_rules! Command {
- ( $name:ident, [ $( $var:ident($inner:ident) => $exec:expr, ) *] ) => {
+ ( $name:ident, [ $( $(#[$doc:meta])* $var:ident$(($inner:ty))? => $exec:expr, ) *] ) => {
#[derive(Debug, PartialEq, structopt::StructOpt)]
pub enum $name {
$(
- $var($inner),
+ $(#[$doc])*
+ $var$(($inner))?,
)*
}
@@ -41,7 +50,7 @@ macro_rules! Command {
) -> crate::Result<()> {
match self {
$(
- $name::$var(args) => $exec(ctx, args),
+ $name::$var$((tr!(args, $inner)))? => $exec(ctx $(,tr!(args, $inner))?),
)*
}
}