aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/setups/structural_renderer.rs
blob: af3ed9167b506601dda17f66231ecf8d12cfcb78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
        });
    }
}