From 9b4cffd48482481691f782e74a4726294043bc57 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 19 Jul 2026 00:21:23 +0800 Subject: feat(picker): extract remains constant and consolidate imports Move the inline `remains_arg` definition into a shared public constant `REMAINS` and update all consumers to import it from the new location. --- mingling/src/setups/picker/basic.rs | 7 +++++-- mingling/src/setups/picker/consts.rs | 15 ++++++++++++++- mingling/src/setups/picker/structural_renderer.rs | 12 +++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'mingling/src/setups/picker') diff --git a/mingling/src/setups/picker/basic.rs b/mingling/src/setups/picker/basic.rs index 0539a09..318edbd 100644 --- a/mingling/src/setups/picker/basic.rs +++ b/mingling/src/setups/picker/basic.rs @@ -1,7 +1,10 @@ -use arg_picker::{IntoPicker, PickerArg, PickerArgs, value::Flag}; +use arg_picker::{IntoPicker, PickerArg, value::Flag}; use mingling_core::{Program, ProgramCollect, setup::ProgramSetup}; -use crate::setups::picker::{CONFIRM_FLAG, HELP_FLAG, QUIET_FLAG}; +use crate::{ + setup::picker::REMAINS, + setups::picker::{CONFIRM_FLAG, HELP_FLAG, QUIET_FLAG}, +}; /// Helper: picks a boolean flag from the program arguments, calls `f` with the /// flag value, then replaces the program arguments with the remaining args. diff --git a/mingling/src/setups/picker/consts.rs b/mingling/src/setups/picker/consts.rs index e254b4f..5e93f3f 100644 --- a/mingling/src/setups/picker/consts.rs +++ b/mingling/src/setups/picker/consts.rs @@ -1,6 +1,19 @@ use std::marker::PhantomData; -use arg_picker::{PickerArg, value::Flag}; +use arg_picker::{PickerArg, PickerArgs, value::Flag}; + +/// Remaining positional arguments (anything not consumed as an option). +/// - `full`: `[]` (empty — not triggered by any `--` prefix). +/// - `short`: (none) +/// - `positional`: `false` (this is a meta‑argument that collects everything left). +/// This constant is used internally to access any leftover arguments after +/// all defined flags/options have been processed. +pub const REMAINS: PickerArg = PickerArg:: { + full: &[], + short: None, + positional: false, + internal_type: PhantomData, +}; /// Help flag: display usage information. /// - `full`: `["help"]` diff --git a/mingling/src/setups/picker/structural_renderer.rs b/mingling/src/setups/picker/structural_renderer.rs index 69f05f1..8e5eac6 100644 --- a/mingling/src/setups/picker/structural_renderer.rs +++ b/mingling/src/setups/picker/structural_renderer.rs @@ -1,8 +1,11 @@ -use arg_picker::{IntoPicker, PickerArg, PickerArgs}; +use arg_picker::IntoPicker; use mingling_core::{Program, ProgramCollect, setup::ProgramSetup}; -use crate::setups::picker::{ - JSON_FLAG, JSON_PRETTY_FLAG, RON_FLAG, RON_PRETTY_FLAG, TOML_FLAG, YAML_FLAG, +use crate::{ + setup::picker::REMAINS, + setups::picker::{ + JSON_FLAG, JSON_PRETTY_FLAG, RON_FLAG, RON_PRETTY_FLAG, TOML_FLAG, YAML_FLAG, + }, }; /// Sets up the structural renderer for the program: @@ -47,7 +50,6 @@ fn process_renderer_flags(args: Vec, program: &mut Program) -> Vec where C: ProgramCollect, { - let remains_arg = PickerArg::::new(&[], None, true); let (json, json_pretty, yaml, toml, ron, ron_pretty, remains) = args .pick(&JSON_FLAG) .pick(&JSON_PRETTY_FLAG) @@ -55,7 +57,7 @@ where .pick(&TOML_FLAG) .pick(&RON_FLAG) .pick(&RON_PRETTY_FLAG) - .pick(&remains_arg) + .pick(&REMAINS) .unwrap(); #[cfg(feature = "json_serde_fmt")] -- cgit