diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-16 04:08:09 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-16 05:25:21 +0800 |
| commit | ea6dda762aa147ebcbc29b269e65b78dd046f4dd (patch) | |
| tree | 9bf354ddc8d7b95162f3ae75e9800313eef1a26f /mingling_picker/src | |
| parent | 0bded81c4e205e387998bf64087acfc39cf70e3e (diff) | |
feat(mingling_picker): replace bool Matcher with FlagMatcherfeat/picker2
Rename `bool_matcher` module to `flag_matcher` and introduce a dedicated
`FlagMatcher` struct, moving matching logic away from the `bool` type
itself
Diffstat (limited to 'mingling_picker/src')
| -rw-r--r-- | mingling_picker/src/builtin/pick_bool.rs | 5 | ||||
| -rw-r--r-- | mingling_picker/src/parselib.rs | 3 | ||||
| -rw-r--r-- | mingling_picker/src/parselib/flag_matcher.rs (renamed from mingling_picker/src/parselib/bool_matcher.rs) | 10 |
3 files changed, 14 insertions, 4 deletions
diff --git a/mingling_picker/src/builtin/pick_bool.rs b/mingling_picker/src/builtin/pick_bool.rs index 65efe47..673f2a3 100644 --- a/mingling_picker/src/builtin/pick_bool.rs +++ b/mingling_picker/src/builtin/pick_bool.rs @@ -1,4 +1,5 @@ -use crate::{parselib::Matcher, pickable_needed::*}; +use crate::parselib::{FlagMatcher, Matcher}; +use crate::pickable_needed::*; impl<'a> Pickable<'a> for bool { fn get_attr(_: &'a PickerFlag<'a, Self>) -> PickerFlagAttr { @@ -6,7 +7,7 @@ impl<'a> Pickable<'a> for bool { } fn tag(ctx: TagPhaseContext) -> Vec<usize> { - <bool as Matcher>::match_all(ctx.into()) + FlagMatcher::match_all(ctx.into()) } fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> { diff --git a/mingling_picker/src/parselib.rs b/mingling_picker/src/parselib.rs index 5950c9d..cf550b7 100644 --- a/mingling_picker/src/parselib.rs +++ b/mingling_picker/src/parselib.rs @@ -1,4 +1,5 @@ -mod bool_matcher; +mod flag_matcher; +pub use flag_matcher::*; mod style; pub use style::*; diff --git a/mingling_picker/src/parselib/bool_matcher.rs b/mingling_picker/src/parselib/flag_matcher.rs index cbcb111..af890b9 100644 --- a/mingling_picker/src/parselib/bool_matcher.rs +++ b/mingling_picker/src/parselib/flag_matcher.rs @@ -4,7 +4,15 @@ use crate::{ vec_string_slice, }; -impl Matcher for bool { +/// `FlagMatcher` is used to match flags in command-line arguments. +/// +/// Flags typically start with `-` or `--` (e.g., `-h`, `--help`), +/// and do not carry additional values. This matcher is responsible for finding +/// these flags in the argument list, taking into account that flags after `--` +/// (end-of-options marker) should not be matched. +pub struct FlagMatcher; + +impl Matcher for FlagMatcher { fn on_match_one( args: &[MaskedArg], style: &ParserStyle, |
