summaryrefslogtreecommitdiff
path: root/mingling_core
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-04 18:53:02 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-04 18:53:02 +0800
commit60c290fbbf0e649b9bf7d3b06e0146499f94a40b (patch)
treee1e180e8806c5a12499c0939499dbd6c90f8b31d /mingling_core
parentf0475c2207181c13dabcd4e78a163cde70573ade (diff)
Handle empty flag in special_arguments macro
Diffstat (limited to 'mingling_core')
-rw-r--r--mingling_core/src/program/flag.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/mingling_core/src/program/flag.rs b/mingling_core/src/program/flag.rs
index edc3dfd..41e8060 100644
--- a/mingling_core/src/program/flag.rs
+++ b/mingling_core/src/program/flag.rs
@@ -141,7 +141,7 @@ macro_rules! special_arguments {
while i < $args.len() {
if &$args[i] == flag {
$args.remove(i);
- while i < $args.len() && !$args[i].starts_with('-') {
+ while i < $args.len() && (flag.is_empty() || !$args[i].starts_with('-')) {
values.push($args[i].clone());
$args.remove(i);
}
@@ -149,6 +149,11 @@ macro_rules! special_arguments {
}
i += 1;
}
+ if flag.is_empty() {
+ while !$args.is_empty() && !$args[0].starts_with('-') {
+ values.push($args.remove(0));
+ }
+ }
values
}};
}
@@ -448,6 +453,17 @@ mod tests {
let result = special_arguments!(args, "--list");
assert_eq!(result, Vec::<String>::new());
assert_eq!(args, vec!["-a", "-b", "--next", "1"]);
+
+ // Test extracting with empty flag
+ let mut args = vec![
+ "a".to_string(),
+ "b".to_string(),
+ "--next".to_string(),
+ "1".to_string(),
+ ];
+ let result = special_arguments!(args, "");
+ assert_eq!(result, vec!["a", "b"]);
+ assert_eq!(args, vec!["--next", "1"]);
}
}