diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-26 06:27:16 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-26 06:41:01 +0800 |
| commit | d1a74ce57e5be72436376a829e9c7e1e7c1c561b (patch) | |
| tree | 6ac923671fc09f1c47b613869d793ed3e04b91db /mingling/src/setups/structural_renderer.rs | |
| parent | e735671acb3a81e1b7e334e56b9ef3963ba0c2fc (diff) | |
refactor(general_renderer): rename to structural_renderer
Diffstat (limited to 'mingling/src/setups/structural_renderer.rs')
| -rw-r--r-- | mingling/src/setups/structural_renderer.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/mingling/src/setups/structural_renderer.rs b/mingling/src/setups/structural_renderer.rs new file mode 100644 index 0000000..af3ed91 --- /dev/null +++ b/mingling/src/setups/structural_renderer.rs @@ -0,0 +1,61 @@ +use mingling_core::{Program, ProgramCollect, setup::ProgramSetup}; + +/// Sets up the structural renderer for the program: +/// +/// - Adds a `--renderer` global argument to specify the renderer type +pub struct StructuralRendererSimpleSetup; + +impl<C> ProgramSetup<C> for StructuralRendererSimpleSetup +where + C: ProgramCollect<Enum = C>, +{ + fn setup(self, program: &mut Program<C>) { + program.global_argument("--renderer", |p, renderer| { + p.structural_renderer_name = renderer.into(); + }); + } +} + +/// Sets up the structural renderer for the program: +/// +/// - Adds global flags to specify the renderer type: +/// * `--json` for JSON output +/// * `--json-pretty` for pretty-printed JSON output +/// * `--yaml` for YAML output +/// * `--toml` for TOML output +/// * `--ron` for RON output +/// * `--ron-pretty` for pretty-printed RON output +pub struct StructuralRendererSetup; + +impl<C> ProgramSetup<C> for StructuralRendererSetup +where + C: ProgramCollect<Enum = C>, +{ + #[allow(unused_variables)] + fn setup(self, program: &mut Program<C>) { + #[cfg(feature = "json_serde_fmt")] + program.global_flag("--json", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::Json; + }); + #[cfg(feature = "json_serde_fmt")] + program.global_flag("--json-pretty", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::JsonPretty; + }); + #[cfg(feature = "yaml_serde_fmt")] + program.global_flag("--yaml", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::Yaml; + }); + #[cfg(feature = "toml_serde_fmt")] + program.global_flag("--toml", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::Toml; + }); + #[cfg(feature = "ron_serde_fmt")] + program.global_flag("--ron", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::Ron; + }); + #[cfg(feature = "ron_serde_fmt")] + program.global_flag("--ron-pretty", |p| { + p.structural_renderer_name = crate::StructuralRendererSetting::RonPretty; + }); + } +} |
