summaryrefslogtreecommitdiff
path: root/src/arg_util.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-07 11:51:11 +0000
committerDaniel Mueller <deso@posteo.net>2020-01-07 11:51:11 +0000
commitbf6dd8ec388512f5e56b888fb0407f6e83f604c5 (patch)
tree84e3b3442968f21331a2de5dcaf52bd6b3e742c9 /src/arg_util.rs
parent31fffa2fe2ad77215be285ab963d0c3565b32ff2 (diff)
downloadnitrocli-bf6dd8ec388512f5e56b888fb0407f6e83f604c5.tar.gz
nitrocli-bf6dd8ec388512f5e56b888fb0407f6e83f604c5.tar.bz2
Refactor the Enum! macro into Enum! and Command!
For an easier transition to structopt, this patch splits the two cases of the Enum! macro into two separate macros (that internally both call the new enum_int! macro).
Diffstat (limited to 'src/arg_util.rs')
-rw-r--r--src/arg_util.rs32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/arg_util.rs b/src/arg_util.rs
index e2e7b1d..56f8758 100644
--- a/src/arg_util.rs
+++ b/src/arg_util.rs
@@ -1,7 +1,7 @@
// arg_util.rs
// *************************************************************************
-// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) *
+// * Copyright (C) 2019-2020 Daniel Mueller (deso@posteo.net) *
// * *
// * This program is free software: you can redistribute it and/or modify *
// * it under the terms of the GNU General Public License as published by *
@@ -24,13 +24,16 @@ macro_rules! count {
}
}
-/// A macro for generating an enum with a set of simple (i.e., no
-/// parameters) variants and their textual representations.
-// TODO: Right now we hard code the derives we create. We may want to
-// make this set configurable.
-macro_rules! Enum {
+macro_rules! Command {
( $name:ident, [ $( $var:ident => ($str:expr, $exec:expr), ) *] ) => {
- Enum! {$name, [
+ #[derive(Debug, PartialEq)]
+ pub enum $name {
+ $(
+ $var,
+ )*
+ }
+
+ enum_int! {$name, [
$( $var => $str, )*
]}
@@ -49,6 +52,13 @@ macro_rules! Enum {
}
}
};
+}
+
+/// A macro for generating an enum with a set of simple (i.e., no
+/// parameters) variants and their textual representations.
+// TODO: Right now we hard code the derives we create. We may want to
+// make this set configurable.
+macro_rules! Enum {
( $name:ident, [ $( $var:ident => $str:expr, ) *] ) => {
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum $name {
@@ -57,6 +67,14 @@ macro_rules! Enum {
)*
}
+ enum_int! {$name, [
+ $( $var => $str, )*
+ ]}
+ };
+}
+
+macro_rules! enum_int {
+ ( $name:ident, [ $( $var:ident => $str:expr, ) *] ) => {
impl $name {
#[allow(unused)]
pub fn all(&self) -> [$name; count!($($var),*) ] {