about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lib.rs45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9d8dd81..f9c6299 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -198,14 +198,14 @@ pub(crate) fn format_parse_fail(string: Cow<'static, str>, key: &str, arg: &str)
 }
 
 #[macro_export]
-macro_rules! args {
-	($name:ident as $($key:literal $(=$arg:literal)? $(?$help:literal)?),*) => {
-		let $name = vec![
-			$(
-				Argument::new($key)$(.arg($arg))?$(.help($help))?
-			),*
-		];
+macro_rules! arg {
+	($key:literal $(=$arg:literal)? $(?$help:literal)?) => {
+		Argument::new($key)$(.arg($arg))?$(.help($help))?
 	};
+
+	([$($key:literal),+] $(=$arg:literal)? $(?$help:literal)?) => {
+		Argument::new([$($key),+])$(.arg($arg))?$(.help($help))?
+	}
 }
 
 #[derive(Debug, PartialEq)]
@@ -297,29 +297,30 @@ macro_rules! impl_boxxed {
 	}
 }
 
-impl_boxxed!(2, 3, 4, 5);
+impl_boxxed!(1, 2, 3, 4, 5);
 
 #[cfg(test)]
 mod test {
 	use crate::Argument;
 
 	#[test]
-	fn args_macro_opt() {
-		args!(arg as "conf");
-
-		assert_eq!(arg, vec![Argument::new("conf")])
+	fn arg_macro_opt() {
+		assert_eq!(arg!("conf"), Argument::new("conf"))
 	}
 
 	#[test]
 	fn args_macro_optarg() {
-		args!(arg as "conf" = "path");
-
-		assert_eq!(arg, vec![Argument::new("conf").arg("path")])
+		assert_eq!(arg!("conf" = "path"), Argument::new("conf").arg("path"))
 	}
 
 	#[test]
 	fn args_macro_multiple() {
-		args!(args as "conf" = "path", "second" = "int", "third" = "float", "flag");
+		let args = vec![
+			arg!("conf" = "path"),
+			arg!("second" = "int"),
+			arg!("third" = "float"),
+			arg!("flag"),
+		];
 
 		let expected = vec![
 			Argument::new("conf").arg("path"),
@@ -333,15 +334,15 @@ mod test {
 
 	#[test]
 	fn args_macro_help() {
-		args!(args as
-			"one" = "arg" ?"Some argument help",
-			"two" = "int" ?"a longer \
-			help message"
-		);
+		let args = vec![
+			arg!("one" = "arg" ?"Some argument help"),
+			arg!(["two", "2"] = "int" ?"a longer \
+				help message"),
+		];
 
 		let expected = vec![
 			Argument::new("one").arg("arg").help("Some argument help"),
-			Argument::new("two")
+			Argument::new(["two", "2"])
 				.arg("int")
 				.help("a longer help message"),
 		];