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(program: &mut Program, flag: &PickerArg) -> bool where C: ProgramCollect, { 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(program: &mut Program, arg: &PickerArg) -> Option where A: for<'a> Pickable<'a> + Default, C: ProgramCollect, { let args = program.take_args(); let (arg, remains) = args.pick(arg).pick(&REMAINS).unpack(); program.replace_args(remains.unwrap().into()); arg }