Skip to content

Commit

Permalink
config: rename AnnotatedValue::path to ::name
Browse files Browse the repository at this point in the history
The field name "path" was confusing because we'll probably add a source file
path to AnnotatedValue.
  • Loading branch information
yuja committed Nov 26, 2024
1 parent 14798d3 commit e029e8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
3 changes: 1 addition & 2 deletions cli/src/commands/config/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ pub fn cmd_config_list(
fn config_template_language() -> GenericTemplateLanguage<'static, AnnotatedValue> {
type L = GenericTemplateLanguage<'static, AnnotatedValue>;
let mut language = L::new();
// "name" instead of "path" to avoid confusion with the source file path
language.add_keyword("name", |self_property| {
let out_property = self_property.map(|annotated| annotated.path.to_string());
let out_property = self_property.map(|annotated| annotated.name.to_string());
Ok(L::wrap_string(out_property))
});
language.add_keyword("value", |self_property| {
Expand Down
27 changes: 14 additions & 13 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ pub enum ConfigEnvError {
#[derive(Clone, Debug, PartialEq)]
pub struct AnnotatedValue {
/// Dotted name path to the configuration variable.
pub path: ConfigNamePathBuf,
pub name: ConfigNamePathBuf,
/// Configuration value.
pub value: config::Value,
/// Source of the configuration value.
pub source: ConfigSource,
// TODO: add source file path
/// True if this value is overridden in higher precedence layers.
pub is_overridden: bool,
}
Expand Down Expand Up @@ -198,19 +199,19 @@ pub fn resolved_config_values(
continue;
};
let mut config_stack = vec![(filter_prefix.clone(), &top_value)];
while let Some((path, value)) = config_stack.pop() {
while let Some((name, value)) = config_stack.pop() {
match &value.kind {
config::ValueKind::Table(table) => {
// TODO: Remove sorting when config crate maintains deterministic ordering.
for (k, v) in table.iter().sorted_by_key(|(k, _)| *k).rev() {
let mut key_path = path.clone();
key_path.push(k);
config_stack.push((key_path, v));
let mut sub_name = name.clone();
sub_name.push(k);
config_stack.push((sub_name, v));
}
}
_ => {
config_vals.push(AnnotatedValue {
path,
name,
value: value.to_owned(),
source,
// Note: Value updated below.
Expand All @@ -223,9 +224,9 @@ pub fn resolved_config_values(

// Walk through config values in reverse order and mark each overridden value as
// overridden.
let mut keys_found = HashSet::new();
let mut names_found = HashSet::new();
for val in config_vals.iter_mut().rev() {
val.is_overridden = !keys_found.insert(&val.path);
val.is_overridden = !names_found.insert(&val.name);
}

Ok(config_vals)
Expand Down Expand Up @@ -776,7 +777,7 @@ mod tests {
@r#"
[
AnnotatedValue {
path: ConfigNamePathBuf(
name: ConfigNamePathBuf(
[
Key {
key: "user",
Expand Down Expand Up @@ -814,7 +815,7 @@ mod tests {
is_overridden: true,
},
AnnotatedValue {
path: ConfigNamePathBuf(
name: ConfigNamePathBuf(
[
Key {
key: "user",
Expand Down Expand Up @@ -852,7 +853,7 @@ mod tests {
is_overridden: false,
},
AnnotatedValue {
path: ConfigNamePathBuf(
name: ConfigNamePathBuf(
[
Key {
key: "user",
Expand Down Expand Up @@ -921,7 +922,7 @@ mod tests {
@r#"
[
AnnotatedValue {
path: ConfigNamePathBuf(
name: ConfigNamePathBuf(
[
Key {
key: "test-table1",
Expand Down Expand Up @@ -959,7 +960,7 @@ mod tests {
is_overridden: false,
},
AnnotatedValue {
path: ConfigNamePathBuf(
name: ConfigNamePathBuf(
[
Key {
key: "test-table1",
Expand Down

0 comments on commit e029e8d

Please sign in to comment.