use std::{ffi::OsStr, path::Path};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConfigFormat {
Yaml,
Toml,
Json,
}
impl ConfigFormat {
pub fn from_path(path: impl AsRef<Path>) -> Self {
match path.as_ref().extension().and_then(OsStr::to_str) {
Some("toml") => Self::Toml,
Some("json" | "json5") => Self::Json,
Some("yaml" | "yml") | Some(_) | None => Self::Yaml,
}
}
}
pub(crate) fn yaml_options() -> confique::yaml::FormatOptions {
let mut options = confique::yaml::FormatOptions::default();
options.indent = 2;
options.general.comments = true;
options.general.env_keys = true;
options.general.nested_field_gap = 1;
options
}
pub(crate) fn toml_options() -> confique::toml::FormatOptions {
let mut options = confique::toml::FormatOptions::default();
options.general.comments = true;
options.general.env_keys = true;
options.general.nested_field_gap = 1;
options
}
pub(crate) fn json5_options() -> confique::json5::FormatOptions {
let mut options = confique::json5::FormatOptions::default();
options.indent = 2;
options.general.comments = true;
options.general.env_keys = true;
options.general.nested_field_gap = 1;
options
}