-
Notifications
You must be signed in to change notification settings - Fork 52
Fix: Merge variable tables instead of bailing #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This allows to have nested tables for variables.
src/config.rs
Outdated
@@ -331,7 +331,19 @@ fn merge_configuration_files( | |||
|
|||
for (variable_name, variable_value) in package.variables { | |||
if first_package.variables.contains_key(&variable_name) { | |||
anyhow::bail!("variable {:?} already encountered", variable_name); | |||
// Panic safety: Already checked via `contains_key` above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be rewritten like so:
- if first_package.variables.contains_key(&variable_name) {
- // Panic safety: Already checked via `contains_key` above
- let mut first_value = first_package.variables.get_mut(&variable_name).unwrap();
- match (&mut first_value, &variable_value) {
+ if let Some(first_value) = first_package.variables.get_mut(&variable_name).as_mut() {
+ match (&first_value, &variable_value) {
src/config.rs
Outdated
let mut first_value = first_package.variables.get_mut(&variable_name).unwrap(); | ||
match (&mut first_value, &variable_value) { | ||
(toml::Value::Table(_a), toml::Value::Table(_b)) => { | ||
info!("Merging {:?} tables", variable_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be trace!
, not info!
since it shouldn't appear with just a single -v
, it fits more into -vvv
category.
See above comments and make sure to run |
I fixed the issues mentioned above. |
The code could be simplified even more, I pushed a commit that implements it with the simplification. Thanks for opening the PR, I wouldn't have gotten around to it otherwise :) |
Yeah, me neither. (I was the OP of the other PR.) Thanks :) |
Fix for #64:
This fix replaces the duplicate
merge_tables
function with the already existingrecursive_extend_map
function. I wasn't able to add unit tests because I don't know any Rust. From my testing this solution works, but please take a look at it before merging and let me know if there are any issues.