opendev_models/config/
formatter.rs1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(untagged)]
13pub enum FormatterConfig {
14 Disabled(bool),
16 Custom(FormatterOverrides),
18}
19
20impl Default for FormatterConfig {
21 fn default() -> Self {
22 FormatterConfig::Custom(FormatterOverrides::default())
23 }
24}
25
26impl FormatterConfig {
27 pub fn is_default(&self) -> bool {
29 matches!(self, FormatterConfig::Custom(o) if o.overrides.is_empty())
30 }
31
32 pub fn is_disabled(&self) -> bool {
34 matches!(self, FormatterConfig::Disabled(false))
35 }
36
37 pub fn overrides(&self) -> &HashMap<String, FormatterOverride> {
39 match self {
40 FormatterConfig::Custom(o) => &o.overrides,
41 FormatterConfig::Disabled(_) => {
42 static EMPTY: std::sync::LazyLock<HashMap<String, FormatterOverride>> =
43 std::sync::LazyLock::new(HashMap::new);
44 &EMPTY
45 }
46 }
47 }
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize)]
52pub struct FormatterOverrides {
53 #[serde(flatten)]
54 pub overrides: HashMap<String, FormatterOverride>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct FormatterOverride {
60 #[serde(default)]
62 pub disabled: bool,
63 #[serde(default, skip_serializing_if = "Vec::is_empty")]
65 pub command: Vec<String>,
66 #[serde(default, skip_serializing_if = "Vec::is_empty")]
68 pub extensions: Vec<String>,
69 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
71 pub environment: HashMap<String, String>,
72}