use std::collections::BTreeMap;
use crate::loader::SourceKind;
use super::super::paths::normalize_metadata_path;
use super::super::{EnvDecoder, FieldMetadata, MergeStrategy};
impl FieldMetadata {
#[must_use]
pub fn new(path: impl Into<String>) -> Self {
Self {
path: normalize_metadata_path(&path.into()),
aliases: Vec::new(),
secret: false,
env: None,
env_decode: None,
doc: None,
example: None,
deprecated: None,
has_default: false,
merge: MergeStrategy::Merge,
merge_explicit: false,
allowed_sources: None,
denied_sources: None,
validations: Vec::new(),
validation_configs: BTreeMap::new(),
}
}
#[must_use]
pub fn alias(mut self, alias: impl Into<String>) -> Self {
self.aliases.push(alias.into());
self
}
#[must_use]
pub fn secret(mut self) -> Self {
self.secret = true;
self
}
#[must_use]
pub fn env(mut self, env: impl Into<String>) -> Self {
self.env = Some(env.into());
self
}
#[must_use]
pub fn env_decoder(mut self, decoder: EnvDecoder) -> Self {
self.env_decode = Some(decoder);
self
}
#[must_use]
pub fn doc(mut self, doc: impl Into<String>) -> Self {
self.doc = Some(doc.into());
self
}
#[must_use]
pub fn example(mut self, example: impl Into<String>) -> Self {
self.example = Some(example.into());
self
}
#[must_use]
pub fn deprecated(mut self, note: impl Into<String>) -> Self {
self.deprecated = Some(note.into());
self
}
#[must_use]
pub fn defaulted(mut self) -> Self {
self.has_default = true;
self
}
#[must_use]
pub fn merge_strategy(mut self, merge: MergeStrategy) -> Self {
self.merge = merge;
self.merge_explicit = true;
self
}
#[must_use]
pub fn allow_sources<I>(mut self, sources: I) -> Self
where
I: IntoIterator<Item = SourceKind>,
{
self.allowed_sources = Some(sources.into_iter().collect());
self
}
#[must_use]
pub fn deny_sources<I>(mut self, sources: I) -> Self
where
I: IntoIterator<Item = SourceKind>,
{
self.denied_sources = Some(sources.into_iter().collect());
self
}
}