From f10ee79ddc2b0a541f1011aa395990df21e456b5 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 01:12:18 +0000 Subject: config: files, arguments and layers, by a program's own options What reads a configuration moves to the crate config, as it was, so that other programs read theirs alike: * option: Kind, OptionSpec, and Schema: a program's options, those that can't be combined, and those that are gone; * file: TOML and JSON files, their includes and unsets; * arguments: the options as arguments, --config and --unset, and files and arguments put together (merged); * layer: values and where they came from, a later source over the earlier ones (overlay), what a value was made of (Sources); * units: durations and sizes as operators write them, which continuum keeps under crate::units. Each takes the schema it reads by, where continuum's code went by its own tables: the node's is config::SCHEMA, a party's client's config::PARTY. Whether a value is shown goes by the schema read by, so an option of the node is no secret for being one of the client's. continuum keeps its options, the settings they make, their checks and the report; its tests of files and layers stay, by the node's options, and the crate has one by a schema of its own. --- crates/config/src/import.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'crates/config/src/import.rs') diff --git a/crates/config/src/import.rs b/crates/config/src/import.rs index a9ad603..04d396f 100644 --- a/crates/config/src/import.rs +++ b/crates/config/src/import.rs @@ -817,24 +817,13 @@ mod tests { assert!(failing.fetch().is_err()); } - /// A directory of a test's files, removed with it. - struct Scratch(PathBuf); + use crate::testing::Scratch; - impl Scratch { - fn new(name: &str) -> Scratch { - let dir = - std::env::temp_dir().join(format!("config-import-{name}-{}", std::process::id())); - let _ = std::fs::remove_dir_all(&dir); - std::fs::create_dir_all(&dir).unwrap(); - Scratch(dir) - } - - /// A file holding `content`: its name. - fn file(&self, name: &str, content: &str) -> String { - std::fs::write(self.0.join(name), content).unwrap(); - name.to_owned() - } + trait Fetch { + fn fetch(&self, raw: &str) -> Result; + } + impl Fetch for Scratch { /// What a command-line value gives, read in this directory. fn fetch(&self, raw: &str) -> Result { let Raw::Import(mut importer) = parse_argument(raw) else { @@ -936,12 +925,6 @@ mod tests { assert!(expand("a${cmd+raw:cat key}", Some(&scratch.0)).is_err()); } - impl Drop for Scratch { - fn drop(&mut self) { - let _ = std::fs::remove_dir_all(&self.0); - } - } - #[test] fn the_parts_of_what_an_importer_names() { let text = |text: &str| Part::Text(text.to_owned()); -- cgit v1.3.1