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/layer.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/layer.rs')
| -rw-r--r-- | crates/config/src/layer.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/config/src/layer.rs b/crates/config/src/layer.rs index 783bcb0..6693009 100644 --- a/crates/config/src/layer.rs +++ b/crates/config/src/layer.rs @@ -6,7 +6,6 @@ use std::path::{Path, PathBuf}; use anyhow::{Result, anyhow, bail}; use serde_json::Value as JsonValue; -use tracing::{debug, info, warn}; use crate::import::{self, Imported}; use crate::option::{Kind, OptionSpec, Schema, from_text}; @@ -106,10 +105,14 @@ pub enum Overlay { } /// Puts `entry` for `name` into `layer`, which holds earlier sources, logging what it -/// replaces and dropping earlier values it can't be combined with. +/// replaces (with the feature `tracing`) and dropping earlier values it can't be combined +/// with. pub fn overlay(layer: &mut Layer, name: String, entry: Entry, how: Overlay, schema: &Schema) { + #[cfg(not(feature = "tracing"))] + let log = |_: &str, _: &str, _: &Entry| {}; + #[cfg(feature = "tracing")] let log = |message: &str, option: &str, previous: &Entry| match how { - Overlay::IncludeOverInclude => warn!( + Overlay::IncludeOverInclude => tracing::warn!( option, value = %entry.shown(schema.secret(&name)), from = %entry.origin, @@ -117,13 +120,13 @@ pub fn overlay(layer: &mut Layer, name: String, entry: Entry, how: Overlay, sche overridden_from = %previous.origin, "{message}" ), - Overlay::FileOverFile => debug!( + Overlay::FileOverFile => tracing::debug!( option, from = %entry.origin, overrides = %previous.origin, "{message}" ), - Overlay::ArgumentOverFile => info!( + Overlay::ArgumentOverFile => tracing::info!( option, value = %entry.shown(schema.secret(&name)), overrides = %previous.shown(schema.secret(option)), @@ -277,6 +280,7 @@ pub fn resolve_file_value( /// `T` read from the values `merged` sets, each option's by its name: those unset take /// `T`'s defaults. +#[cfg(feature = "serde")] pub fn read<T: serde::de::DeserializeOwned>(merged: &Layer) -> Result<T> { let object: serde_json::Map<String, JsonValue> = merged .iter() |
