aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/setups/picker/structural_renderer.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/setups/picker/structural_renderer.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/setups/picker/structural_renderer.rs')
-rw-r--r--mingling/src/setups/picker/structural_renderer.rs93
1 files changed, 40 insertions, 53 deletions
diff --git a/mingling/src/setups/picker/structural_renderer.rs b/mingling/src/setups/picker/structural_renderer.rs
index 8e5eac6..1fa48fd 100644
--- a/mingling/src/setups/picker/structural_renderer.rs
+++ b/mingling/src/setups/picker/structural_renderer.rs
@@ -1,11 +1,8 @@
-use arg_picker::IntoPicker;
use mingling_core::{Program, ProgramCollect, setup::ProgramSetup};
use crate::{
- setup::picker::REMAINS,
- setups::picker::{
- JSON_FLAG, JSON_PRETTY_FLAG, RON_FLAG, RON_PRETTY_FLAG, TOML_FLAG, YAML_FLAG,
- },
+ consts::RENDERER_ARG,
+ picker::{pick_global_argument, pick_global_flag},
};
/// Sets up the structural renderer for the program:
@@ -18,9 +15,9 @@ where
C: ProgramCollect<Enum = C>,
{
fn setup(self, program: &mut Program<C>) {
- program.global_argument("--renderer", |p, renderer| {
- p.structural_renderer_name = renderer.into();
- });
+ if let Some(renderer) = pick_global_argument(program, &RENDERER_ARG) {
+ program.structural_renderer_name = renderer.into();
+ }
}
}
@@ -33,6 +30,17 @@ where
/// * `--toml` for TOML output
/// * `--ron` for RON output
/// * `--ron-pretty` for pretty-printed RON output
+///
+/// # Flag priority
+///
+/// If multiple flags are specified, the last matching flag in the following
+/// declaration order takes precedence:
+/// 1. `--json`
+/// 2. `--json-pretty`
+/// 3. `--yaml`
+/// 4. `--toml`
+/// 5. `--ron`
+/// 6. `--ron-pretty`
pub struct StructuralRendererSetup;
impl<C> ProgramSetup<C> for StructuralRendererSetup
@@ -40,50 +48,29 @@ where
C: ProgramCollect<Enum = C>,
{
fn setup(self, program: &mut Program<C>) {
- let args = program.take_args();
- let args = process_renderer_flags(args, program);
- program.replace_args(args);
+ #[cfg(feature = "json_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::JSON_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::Json;
+ }
+ #[cfg(feature = "json_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::JSON_PRETTY_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::JsonPretty;
+ }
+ #[cfg(feature = "yaml_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::YAML_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::Yaml;
+ }
+ #[cfg(feature = "toml_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::TOML_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::Toml;
+ }
+ #[cfg(feature = "ron_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::RON_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::Ron;
+ }
+ #[cfg(feature = "ron_serde_fmt")]
+ if pick_global_flag(program, &crate::consts::RON_PRETTY_FLAG) {
+ program.structural_renderer_name = crate::StructuralRendererSetting::RonPretty;
+ }
}
}
-
-fn process_renderer_flags<C>(args: Vec<String>, program: &mut Program<C>) -> Vec<String>
-where
- C: ProgramCollect<Enum = C>,
-{
- let (json, json_pretty, yaml, toml, ron, ron_pretty, remains) = args
- .pick(&JSON_FLAG)
- .pick(&JSON_PRETTY_FLAG)
- .pick(&YAML_FLAG)
- .pick(&TOML_FLAG)
- .pick(&RON_FLAG)
- .pick(&RON_PRETTY_FLAG)
- .pick(&REMAINS)
- .unwrap();
-
- #[cfg(feature = "json_serde_fmt")]
- if *json {
- program.structural_renderer_name = crate::StructuralRendererSetting::Json;
- }
- #[cfg(feature = "json_serde_fmt")]
- if *json_pretty {
- program.structural_renderer_name = crate::StructuralRendererSetting::JsonPretty;
- }
- #[cfg(feature = "yaml_serde_fmt")]
- if *yaml {
- program.structural_renderer_name = crate::StructuralRendererSetting::Yaml;
- }
- #[cfg(feature = "toml_serde_fmt")]
- if *toml {
- program.structural_renderer_name = crate::StructuralRendererSetting::Toml;
- }
- #[cfg(feature = "ron_serde_fmt")]
- if *ron {
- program.structural_renderer_name = crate::StructuralRendererSetting::Ron;
- }
- #[cfg(feature = "ron_serde_fmt")]
- if *ron_pretty {
- program.structural_renderer_name = crate::StructuralRendererSetting::RonPretty;
- }
-
- remains.into()
-}