diff options
| author | tv <tv@krebsco.de> | 2026-11-29 01:24:49 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 01:24:49 +0000 |
| commit | f568d97b7ad41bdeeb4d07c61fad468bc83ad3f6 (patch) | |
| tree | 4176b4be5bb27fcc6108a0c32c2da4376576a15f /crates/config/src/file.rs | |
| parent | f10ee79ddc2b0a541f1011aa395990df21e456b5 (diff) | |
config: clap, serde, toml and tracing are features, none default
A program names what it uses of the crate:
* clap: the command line (arguments);
* serde: what the values set are read into (layer::read), and
durations and sizes as fields (units::duration_option, …);
* toml: configuration files in TOML; without it a .toml file is
refused, saying so, and files are JSON;
* tracing: what a source replaces of an earlier one's, logged.
continuum names all four.
Diffstat (limited to 'crates/config/src/file.rs')
| -rw-r--r-- | crates/config/src/file.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/crates/config/src/file.rs b/crates/config/src/file.rs index a5ed559..b365623 100644 --- a/crates/config/src/file.rs +++ b/crates/config/src/file.rs @@ -14,7 +14,6 @@ use std::path::{Path, PathBuf}; use anyhow::{Context, Result, anyhow, bail}; use serde_json::{Map as JsonMap, Value as JsonValue}; -use tracing::debug; use crate::import; use crate::layer::{Entry, Layer, Overlay, Provenance, overlay, resolve_file_value, unset_entry}; @@ -59,7 +58,8 @@ fn load_inner(path: &Path, schema: &Schema, loading: &mut Vec<PathBuf>) -> Resul for (include, required) in includes { let include = dir.join(include); if !required && !include.exists() { - debug!(file = %include.display(), "Optional configuration file is missing; skipped"); + #[cfg(feature = "tracing")] + tracing::debug!(file = %include.display(), "Optional configuration file is missing; skipped"); continue; } let included = load_inner(&include, schema, loading) @@ -113,11 +113,18 @@ fn parse(path: &Path) -> Result<JsonMap<String, JsonValue>> { let text = std::fs::read_to_string(path).with_context(|| format!("reading {}", path.display()))?; let value: JsonValue = match path.extension().and_then(|e| e.to_str()) { + #[cfg(feature = "toml")] Some("toml") => { let value: toml::Value = toml::from_str(&text).with_context(|| format!("parsing {}", path.display()))?; serde_json::to_value(value).with_context(|| format!("converting {}", path.display()))? } + #[cfg(not(feature = "toml"))] + Some("toml") => bail!( + "{}: this program reads no TOML (it is built without the config crate's feature \ + toml): use .json", + path.display() + ), Some("json") => { serde_json::from_str(&text).with_context(|| format!("parsing {}", path.display()))? } |
