aboutsummaryrefslogtreecommitdiff
path: root/mingling/src
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-04-14 02:59:38 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-04-14 02:59:38 +0800
commit56c24db7bcd92e2eb9a779bd141fcc73a7c433c0 (patch)
tree2a571cc05942e0308abd6d4d336a66b4bc1cc474 /mingling/src
parent031771110c53ff903046c47882b418a5b4936d5b (diff)
Add `strip_all_flags` method and `operate_args` method
Diffstat (limited to 'mingling/src')
-rw-r--r--mingling/src/parser/args.rs13
-rw-r--r--mingling/src/parser/picker.rs20
2 files changed, 33 insertions, 0 deletions
diff --git a/mingling/src/parser/args.rs b/mingling/src/parser/args.rs
index 2a07e97..9c08d43 100644
--- a/mingling/src/parser/args.rs
+++ b/mingling/src/parser/args.rs
@@ -154,4 +154,17 @@ impl Argument {
let new = Vec::new();
replace(&mut self.vec, new)
}
+
+ /// Removes all arguments that start with a dash ('-')
+ ///
+ /// This method filters out all command-line style flags from the arguments,
+ /// returning a new `Argument` instance containing only non-flag arguments.
+ pub fn strip_all_flags(mut self) -> Self {
+ self.vec = self
+ .vec
+ .into_iter()
+ .filter(|f| !f.starts_with('-'))
+ .collect();
+ self
+ }
}
diff --git a/mingling/src/parser/picker.rs b/mingling/src/parser/picker.rs
index 9258002..d69e27a 100644
--- a/mingling/src/parser/picker.rs
+++ b/mingling/src/parser/picker.rs
@@ -108,6 +108,16 @@ impl<R> Picker<R> {
None => None,
}
}
+
+ /// Applies an operation to the parsed arguments and returns the modified `Picker`.
+ ///
+ /// Takes a closure that receives the current `Argument` and returns a new `Argument`.
+ /// The returned `Argument` replaces the original arguments in the builder.
+ /// This method can be used to modify or transform the parsed arguments before extracting values.
+ pub fn operate_args<F: FnOnce(Argument) -> Argument>(mut self, operation: F) -> Self {
+ self.args = operation(self.args);
+ self
+ }
}
impl<T: Into<Argument>, G> From<T> for Picker<G> {
@@ -189,6 +199,16 @@ macro_rules! define_pick_structs {
self.$final_val = edit(self.$final_val);
self
}
+
+ /// Applies an operation to the parsed arguments and returns the modified `Picker`.
+ ///
+ /// Takes a closure that receives the current `Argument` and returns a new `Argument`.
+ /// The returned `Argument` replaces the original arguments in the builder.
+ /// This method can be used to modify or transform the parsed arguments before extracting values.
+ pub fn operate_args<F: FnOnce(Argument) -> Argument>(mut self, operation: F) -> Self {
+ self.args = operation(self.args);
+ self
+ }
}
};
}