diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-15 02:41:14 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-15 02:41:14 +0800 |
| commit | d3ac40a44c5dec3f56393876c669ce7e0819a69e (patch) | |
| tree | 1005b936500bc4bc1146c52d9cb3da14a5cdf6e9 | |
| parent | fdd26053228593162fd5c41df9cfbc45d0c731b9 (diff) | |
feat(picker): add `mingling_support` feature and `is_flag` field
Rename the `core` feature to `mingling_support` in `mingling_picker` and
propagate it through `mingling_picker_macros`. Add the `is_flag` field
to `PickerTag` to indicate participation in parsing after a `--`
separator. Remove empty `seek.rs` file.
| -rw-r--r-- | mingling/Cargo.toml | 2 | ||||
| -rw-r--r-- | mingling_picker/Cargo.toml | 2 | ||||
| -rw-r--r-- | mingling_picker/src/lib.rs | 4 | ||||
| -rw-r--r-- | mingling_picker/src/parselib/seek.rs | 1 | ||||
| -rw-r--r-- | mingling_picker/src/tag.rs | 18 | ||||
| -rw-r--r-- | mingling_picker_macros/Cargo.toml | 3 | ||||
| -rw-r--r-- | mingling_picker_macros/src/flag.rs | 5 |
7 files changed, 30 insertions, 5 deletions
diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml index 2cd517e..c3f9511 100644 --- a/mingling/Cargo.toml +++ b/mingling/Cargo.toml @@ -50,7 +50,7 @@ dispatch_tree = ["mingling_core/dispatch_tree", "mingling_macros/dispatch_tree"] repl = ["mingling_core/repl", "mingling_macros/repl"] comp = ["mingling_core/comp", "mingling_macros/comp"] parser = ["dep:size"] -picker = ["dep:mingling_picker"] +picker = ["dep:mingling_picker", "mingling_picker/mingling_support"] pathf = ["mingling_core/pathf", "mingling_macros/pathf"] structural_renderer = [ diff --git a/mingling_picker/Cargo.toml b/mingling_picker/Cargo.toml index a585a39..4cbab39 100644 --- a/mingling_picker/Cargo.toml +++ b/mingling_picker/Cargo.toml @@ -9,7 +9,7 @@ readme = "README.md" description = "Mingling's lightweight argument parser" [features] -core = ["dep:mingling_core"] +mingling_support = ["dep:mingling_core", "mingling_picker_macros/mingling_support"] [dependencies] mingling_core = { workspace = true, optional = true } diff --git a/mingling_picker/src/lib.rs b/mingling_picker/src/lib.rs index fa45d71..d2885d9 100644 --- a/mingling_picker/src/lib.rs +++ b/mingling_picker/src/lib.rs @@ -23,8 +23,8 @@ pub mod macros { pub use mingling_picker_macros::*; } -#[cfg(feature = "core")] +#[cfg(feature = "mingling_support")] mod corebind; -#[cfg(feature = "core")] +#[cfg(feature = "mingling_support")] pub use corebind::*; diff --git a/mingling_picker/src/parselib/seek.rs b/mingling_picker/src/parselib/seek.rs deleted file mode 100644 index 8b13789..0000000 --- a/mingling_picker/src/parselib/seek.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/mingling_picker/src/tag.rs b/mingling_picker/src/tag.rs index 6f91630..a64cf6e 100644 --- a/mingling_picker/src/tag.rs +++ b/mingling_picker/src/tag.rs @@ -13,6 +13,7 @@ use crate::{Pickable, PickerFlag}; /// * `positional` - Whether this tag is a positional argument (no `-` or `--` prefix). /// * `optional` - Whether this tag is optional or required. /// * `multi` - Whether this tag can accept multiple values. +/// * `is_flag` - Whether this tag participates in parsing after a `--` separator. pub struct PickerTag<'a> { /// The short form of the tag, e.g. `'n'` for `-n`. pub short: Option<char>, @@ -26,6 +27,8 @@ pub struct PickerTag<'a> { pub optional: bool, /// Whether this tag can accept multiple values. pub multi: bool, + /// Whether this tag participates in parsing after a `--` separator. + pub is_flag: bool, } impl<'a, T> From<PickerFlag<'a, T>> for PickerTag<'a> @@ -53,6 +56,7 @@ where positional: value.positional, optional: false, multi: false, + is_flag: false, } } } @@ -79,6 +83,7 @@ impl<'a, T: Pickable<'a> + Default> From<&'a PickerFlag<'a, T>> for PickerTag<'a positional: value.positional, optional: false, multi: false, + is_flag: false, } } } @@ -93,6 +98,7 @@ impl<'a> PickerTag<'a> { positional: false, optional: false, multi: false, + is_flag: false, } } @@ -132,6 +138,12 @@ impl<'a> PickerTag<'a> { self } + /// Mark the tag as a flag that participates in parsing after `--`. + pub fn with_is_flag(mut self, is_flag: bool) -> Self { + self.is_flag = is_flag; + self + } + /// Set the short flag (e.g., `'n'` for `-n`). pub fn set_short(&mut self, short: char) -> &mut Self { self.short = Some(short); @@ -167,6 +179,12 @@ impl<'a> PickerTag<'a> { self.multi = multi; self } + + /// Set whether this tag participates in parsing after a `--` separator. + pub fn set_is_flag(&mut self, is_flag: bool) -> &mut Self { + self.is_flag = is_flag; + self + } } impl<'a> Default for PickerTag<'a> { diff --git a/mingling_picker_macros/Cargo.toml b/mingling_picker_macros/Cargo.toml index 5bab6e5..58488ea 100644 --- a/mingling_picker_macros/Cargo.toml +++ b/mingling_picker_macros/Cargo.toml @@ -11,6 +11,9 @@ description = "Mingling's lightweight argument parser macros" [lib] proc-macro = true +[features] +mingling_support = [] + [dependencies] syn.workspace = true quote.workspace = true diff --git a/mingling_picker_macros/src/flag.rs b/mingling_picker_macros/src/flag.rs index 0d65382..71302ae 100644 --- a/mingling_picker_macros/src/flag.rs +++ b/mingling_picker_macros/src/flag.rs @@ -69,7 +69,12 @@ pub(crate) fn flag(input: TokenStream) -> TokenStream { }) .unwrap_or(TS2::new()); + #[cfg(feature = "mingling_support")] let import = quote! { ::mingling::picker::PickerFlag }; + + #[cfg(not(feature = "mingling_support"))] + let import = quote! { ::mingling_picker::PickerFlag }; + if ty.is_some() { quote! { #import::<#ty_ts> } } else { |
