From f568d97b7ad41bdeeb4d07c61fad468bc83ad3f6 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 01:24:49 +0000 Subject: config: clap, serde, toml and tracing are features, none default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- crates/config/src/file.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/config/src/file.rs') 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) -> 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> { 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()))? } -- cgit v1.3.1