Skip to content

Commit

Permalink
refactor: rename args
Browse files Browse the repository at this point in the history
  • Loading branch information
fukusuket committed Dec 7, 2024
1 parent d4304ec commit 2458d41
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/yaml_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,38 @@ fn process_value(
pub fn process_yaml(
yaml: &Yaml,
replacements: &HashMap<String, Vec<String>>,
expand_found: &mut u128,
expand_enabled: &mut u128,
expand_count: &mut u128,
expand_enabled_count: &mut u128,
) -> Yaml {
match yaml {
Yaml::Hash(hash) => {
let mut new_hash = Hash::new();
for (key, value) in hash {
if let Yaml::String(key_str) = key {
if key_str.contains("|expand") {
*expand_found += 1;
*expand_count += 1;
let new_key = key_str.replace("|expand", "");
let org_value = value.clone();
let new_value =
process_value(&org_value, replacements, expand_found, expand_enabled);
let new_value = process_value(
&org_value,
replacements,
expand_count,
expand_enabled_count,
);
if org_value != new_value {
*expand_enabled += 1;
*expand_enabled_count += 1;
};
new_hash.insert(Yaml::String(new_key), new_value);
} else {
new_hash.insert(
key.clone(),
process_yaml(value, replacements, expand_found, expand_enabled),
process_yaml(value, replacements, expand_count, expand_enabled_count),
);
}
} else {
new_hash.insert(
key.clone(),
process_yaml(value, replacements, expand_found, expand_enabled),
process_yaml(value, replacements, expand_count, expand_enabled_count),
);
}
}
Expand All @@ -80,7 +84,7 @@ pub fn process_yaml(
Yaml::Array(array) => {
let new_array: Vec<Yaml> = array
.iter()
.map(|item| process_yaml(item, replacements, expand_found, expand_enabled))
.map(|item| process_yaml(item, replacements, expand_count, expand_enabled_count))
.collect();
Yaml::Array(new_array)
}
Expand Down

0 comments on commit 2458d41

Please sign in to comment.