greentic_flow/
schema_mode.rs1use anyhow::{Result, anyhow};
2use std::env;
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6pub enum SchemaMode {
7 Strict,
8 Permissive,
9}
10
11impl SchemaMode {
12 pub fn resolve(cli_permissive: bool) -> Result<Self> {
18 if cli_permissive {
19 return Ok(SchemaMode::Permissive);
20 }
21 match env::var("GREENTIC_FLOW_STRICT") {
22 Ok(val) => match val.as_str() {
23 "0" => Ok(SchemaMode::Permissive),
24 "1" => Ok(SchemaMode::Strict),
25 other => Err(anyhow!(
26 "GREENTIC_FLOW_STRICT must be '0' or '1', got '{other}'"
27 )),
28 },
29 Err(env::VarError::NotPresent) => Ok(SchemaMode::Strict),
30 Err(err) => Err(anyhow!("failed to read GREENTIC_FLOW_STRICT: {err}")),
31 }
32 }
33
34 pub fn is_permissive(&self) -> bool {
35 matches!(self, SchemaMode::Permissive)
36 }
37}