diff --git a/Cargo.lock b/Cargo.lock
index a22ed9f..9d4b74c 100755
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,7 +16,7 @@ checksum = "ea618ded77af626818bde0f0802da7c20d47e38e23e37be40f6f807a76079e82"
[[package]]
name = "scurvy"
-version = "0.4.0"
+version = "0.5.0"
dependencies = [
"camino",
"confindent",
diff --git a/Cargo.toml b/Cargo.toml
index 08c4466..707e3fa 100755
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "scurvy"
-version = "0.4.0"
+version = "0.5.0"
edition = "2024"
[dependencies]
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"),
];
|