diff options
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 => { |
