use std::collections::BTreeMap;
use crate::{MergeStrategy, SourceKind, ValidationLevel, ValidationRule};
pub const ENV_DOCS_FORMAT_VERSION: u32 = 3;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct EnvDocEntry {
pub path: String,
pub env: String,
pub ty: String,
pub required: bool,
pub secret: bool,
pub description: Option<String>,
pub example: Option<String>,
pub deprecated: Option<String>,
pub aliases: Vec<String>,
pub has_default: bool,
pub merge: MergeStrategy,
pub allowed_sources: Vec<SourceKind>,
pub denied_sources: Vec<SourceKind>,
pub validations: Vec<ValidationRule>,
pub validation_levels: BTreeMap<String, ValidationLevel>,
pub validation_messages: BTreeMap<String, String>,
pub validation_tags: BTreeMap<String, Vec<String>>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct EnvDocsReport {
pub format_version: u32,
pub entries: Vec<EnvDocEntry>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EnvDocOptions {
prefix: Option<String>,
separator: String,
uppercase: bool,
}
impl Default for EnvDocOptions {
fn default() -> Self {
Self {
prefix: None,
separator: "__".to_owned(),
uppercase: true,
}
}
}
impl EnvDocOptions {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn prefixed(prefix: impl Into<String>) -> Self {
Self::default().prefix(prefix)
}
#[must_use]
pub fn prefix(mut self, prefix: impl Into<String>) -> Self {
self.prefix = Some(prefix.into());
self
}
#[must_use]
pub fn separator(mut self, separator: impl Into<String>) -> Self {
let separator = separator.into();
if !separator.is_empty() {
self.separator = separator;
}
self
}
#[must_use]
pub fn preserve_case(mut self) -> Self {
self.uppercase = false;
self
}
#[must_use]
pub fn env_name(&self, path: &str) -> String {
crate::env_name::path_to_env_name(
path,
self.prefix.as_deref(),
&self.separator,
self.uppercase,
)
}
}