flower_core/format.rs
1//! Map a file path's extension onto a `fig::Format`.
2
3use std::path::Path;
4
5use fig::Format;
6
7/// Detect the config format from `path`'s extension, or `None` if unrecognized.
8pub fn detect(path: &Path) -> Option<Format> {
9 let ext = path.extension()?.to_str()?.to_ascii_lowercase();
10 Some(match ext.as_str() {
11 "json" => Format::Json,
12 "jsonc" => Format::Jsonc,
13 "json5" => Format::Json5,
14 "yaml" | "yml" => Format::Yaml,
15 "toml" => Format::Toml,
16 "zon" => Format::Zon,
17 "fig" | "figl" => Format::Fig,
18 _ => return None,
19 })
20}