diff options
| author | tv <tv@krebsco.de> | 2026-12-02 16:24:19 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-02 17:08:52 +0000 |
| commit | 2be9ca2b75d099a9ca04078f2182acda074ed270 (patch) | |
| tree | acd772e1873e566e2022f068628179bbd53eb8e9 /crates/config/src/layer.rs | |
| parent | 1de11da61a106187748c4b79e1d7b63e3b9d172f (diff) | |
config: a configuration names importers of its own
[meta.importer] in a file, or --meta-importer-NAME IMPORTER, names an
importer: NAME:REST, { NAME = "REST" } and a placeholder of that name
are then that importer, with REST as its variable `name`. So what would
be built in for one tool, pass:NAME, is written by who uses it, once:
pass = { command = ["pass", "show", "$(var:name)"] }.
A name counts in every file and argument, wherever it is given; of two
of one name, the later source's. What follows the name goes in as every
variable does, as data. One named may be defined through others, not
through itself. `meta` at the top of a configuration file is what the
configuration says about itself. The argument is spelled as every
option's, the table's keys joined with `-`; as its name is the
configuration's, it is taken off the command line before the command
reads it.
Diffstat (limited to 'crates/config/src/layer.rs')
| -rw-r--r-- | crates/config/src/layer.rs | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/crates/config/src/layer.rs b/crates/config/src/layer.rs index 9871d9b..916acf4 100644 --- a/crates/config/src/layer.rs +++ b/crates/config/src/layer.rs @@ -163,7 +163,17 @@ pub fn overlay(layer: &mut Layer, name: String, entry: Entry, how: Overlay, sche } pub fn from_import(kind: Kind, importer: &import::Importer) -> Result<JsonValue> { - match importer.fetch()? { + from_import_in(kind, importer, &import::Importers::new()) +} + +/// What `importer` gives, as a value of `kind`; `named` are the importers the +/// configuration names. +pub fn from_import_in( + kind: Kind, + importer: &import::Importer, + named: &import::Importers, +) -> Result<JsonValue> { + match importer.fetch_in(&import::Variables::new(), named)? { Imported::Text(text) => from_text(kind, &text), Imported::Json(value) => Ok(value), // As it is: one text, its line breaks kept, read as nothing else. @@ -218,25 +228,36 @@ impl Sources { } } -/// A value from a file, and where its parts came from. +/// A value from a file, and where its parts came from, where no importers are named. pub fn resolve_file_value( spec: &OptionSpec, value: JsonValue, dir: &Path, ) -> Result<(JsonValue, Sources)> { + resolve_file_value_in(spec, value, dir, &import::Importers::new()) +} + +/// A value from a file, and where its parts came from; `named` are the importers the +/// configuration names. +pub fn resolve_file_value_in( + spec: &OptionSpec, + value: JsonValue, + dir: &Path, + named: &import::Importers, +) -> Result<(JsonValue, Sources)> { let mut sources = Sources::default(); let value = match value { - JsonValue::Object(table) => match import::parse_table(&table, dir)? { + JsonValue::Object(table) => match import::parse_table_in(&table, dir, named)? { Some(importer) => { sources.import(&importer); - from_import(spec.kind, &importer)? + from_import_in(spec.kind, &importer, named)? } None => bail!("a table here must be an importer (env, file or command)"), }, JsonValue::String(text) => match import::interpolated(&text, Some(dir)) { Some(importer) => { sources.import(&importer); - from_import(spec.kind, &importer)? + from_import_in(spec.kind, &importer, named)? } None => JsonValue::String(text), }, @@ -245,10 +266,11 @@ pub fn resolve_file_value( for item in items { match item { JsonValue::Object(table) => { - let importer = import::parse_table(&table, dir)?.ok_or_else(|| { - anyhow!("a table here must be an importer (env, file or command)") - })?; - match from_import(Kind::List, &importer)? { + let importer = + import::parse_table_in(&table, dir, named)?.ok_or_else(|| { + anyhow!("a table here must be an importer (env, file or command)") + })?; + match from_import_in(Kind::List, &importer, named)? { JsonValue::Array(more) => values.extend(more), other => values.push(other), } @@ -256,7 +278,7 @@ pub fn resolve_file_value( } JsonValue::String(text) => match import::interpolated(&text, Some(dir)) { Some(importer) => { - values.push(from_import(Kind::Text, &importer)?); + values.push(from_import_in(Kind::Text, &importer, named)?); sources.import(&importer); } None => { |
