aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/picker/global.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-19 00:22:23 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-19 00:27:16 +0800
commit5e460470f6ea2ce31a403b6e936ec2fe8f45312a (patch)
treeec1d675d9544b31ab9382ebbd10bbeda43923cc8 /mingling/src/picker/global.rs
parent9b4cffd48482481691f782e74a4726294043bc57 (diff)
feat: migrate mingling-specific picker code into mingling crate
BREAKING CHANGE: Remove `mingling_support` feature from arg-picker crate. The `EntryPicker` trait and `corebind` module are now part of the mingling crate directly, and `build_pattern1` is now a public method.
Diffstat (limited to 'mingling/src/picker/global.rs')
-rw-r--r--mingling/src/picker/global.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/mingling/src/picker/global.rs b/mingling/src/picker/global.rs
new file mode 100644
index 0000000..c203524
--- /dev/null
+++ b/mingling/src/picker/global.rs
@@ -0,0 +1,35 @@
+use arg_picker::{IntoPicker, Pickable, PickerArg, value::Flag};
+use mingling_core::{Program, ProgramCollect};
+
+use crate::consts::REMAINS;
+
+/// Picks a global flag from the program's arguments.
+///
+/// This function takes ownership of the program's current arguments, picks the specified `flag`
+/// from them, and then returns the remaining arguments back to the program. It returns the
+/// boolean value of the flag.
+pub fn pick_global_flag<C>(program: &mut Program<C>, flag: &PickerArg<Flag>) -> bool
+where
+ C: ProgramCollect<Enum = C>,
+{
+ let args = program.take_args();
+ let (flag, args) = args.pick(flag).pick(&REMAINS).unwrap();
+ program.replace_args(args.into());
+ *flag
+}
+
+/// Picks a global argument from the program's arguments.
+///
+/// This function takes ownership of the program's current arguments, picks the specified `arg`
+/// from them, and then returns the remaining arguments back to the program. It returns the
+/// picked argument value, or `None` if the argument was not present.
+pub fn pick_global_argument<C, A>(program: &mut Program<C>, arg: &PickerArg<A>) -> Option<A>
+where
+ A: for<'a> Pickable<'a> + Default,
+ C: ProgramCollect<Enum = C>,
+{
+ let args = program.take_args();
+ let (arg, remains) = args.pick(arg).pick(&REMAINS).unpack();
+ program.replace_args(remains.unwrap().into());
+ arg
+}