aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mingling_picker/src/builtin/pick_string.rs16
-rw-r--r--mingling_picker/src/parselib/utils.rs25
2 files changed, 29 insertions, 12 deletions
diff --git a/mingling_picker/src/builtin/pick_string.rs b/mingling_picker/src/builtin/pick_string.rs
index 6c11ef3..4a65873 100644
--- a/mingling_picker/src/builtin/pick_string.rs
+++ b/mingling_picker/src/builtin/pick_string.rs
@@ -1,4 +1,4 @@
-use crate::parselib::{ParserStyle, SingleMatcher};
+use crate::parselib::{SingleMatcher, seek_single};
use crate::pickable_needed::*;
impl<'a> Pickable<'a> for String {
@@ -11,17 +11,9 @@ impl<'a> Pickable<'a> for String {
}
fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> {
- match raw_strs.len() {
- 0 => PickerArgResult::NotFound,
- 1 => {
- let s = raw_strs[0];
- let sep = ParserStyle::global_style().value_separator;
- if let Some(pos) = s.rfind(sep) {
- return PickerArgResult::Parsed(s[pos + 1..].to_string());
- }
- PickerArgResult::Parsed(s.to_string())
- }
- _ => PickerArgResult::Parsed(raw_strs[1].to_string()),
+ match seek_single(raw_strs) {
+ Some(v) => PickerArgResult::Parsed(v.to_string()),
+ None => PickerArgResult::NotFound,
}
}
}
diff --git a/mingling_picker/src/parselib/utils.rs b/mingling_picker/src/parselib/utils.rs
index ae3c203..4fd34b7 100644
--- a/mingling_picker/src/parselib/utils.rs
+++ b/mingling_picker/src/parselib/utils.rs
@@ -26,6 +26,31 @@ pub fn build_possible_flags(style: &ParserStyle, arg_info: &PickerArgInfo) -> Ve
possible_flags
}
+/// Extract a single value from the raw strings tagged by [`SingleMatcher`].
+///
+/// Returns `None` if no value is available (empty slice),
+/// the inline value after the style separator if present (eq mode),
+/// or the value directly (positional or flag-following).
+///
+/// This is the standard `pick` helper for all `Single`-type
+/// [`Pickable`](crate::Pickable) implementations.
+#[must_use]
+pub fn seek_single<'a>(raw_strs: &'a [&'a str]) -> Option<&'a str> {
+ match raw_strs.len() {
+ 0 => None,
+ 1 => {
+ let s = raw_strs[0];
+ let sep = ParserStyle::global_style().value_separator;
+ if let Some(pos) = s.rfind(sep) {
+ Some(&s[pos + 1..])
+ } else {
+ Some(s)
+ }
+ }
+ _ => Some(raw_strs[1]),
+ }
+}
+
/// Seeks the index of the end-of-options marker (`--`) in the argument list.
///
/// This function searches for the standard end-of-options separator (`--`)