Skip to content

Feature/control append #48

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

Merged
merged 14 commits into from
Apr 30, 2025
Merged

Feature/control append #48

merged 14 commits into from
Apr 30, 2025

Conversation

nathanhhughes
Copy link
Collaborator

@Schmluk Ended up coming across cases where I needed to (i) have fine-grained control over sequence update semantics (i.e., have some sequences that append when merging, and have some sequence that override) and (ii) start on interpolating values. Aaron and I have been talking about a better solution for the interpolation than tags (right now we can only override a key or value wholesale) but it's too involved to implement at the moment. This mostly has to do with the command line interface, but intention is that this is useful beyond that

Summary of changes:

  • Allows specifying behavior for merging two sequences by tag (!update, !append, !replace)
  • Allows interpolating environment variables by !env VAR
  • Adds an executable that will composite multiple YAML sources from the command line

@nathanhhughes
Copy link
Collaborator Author

@GoldenZephyr also tagging you for review to get your take on the sequence merge semantics

Copy link
Collaborator

@Schmluk Schmluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Many thanks for these features!

@@ -54,6 +55,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(config_utilities::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

add_executable(composite-configs app/composite_configs.cpp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I remember having the discussion whether we want a tool like that and we opted against it at the time, but seems reasonable to have in config_utilities 🙂

@@ -42,12 +42,21 @@

namespace config::internal {

enum class MergeMode {
//! @brief Combine the two trees, recursing into matching sequence entries
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to also specify how conflicts are resolved here, I assume right will overwrite entries in left for entries with matching keys?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can document the behavior better, I just forget if I changed anything with how keys are handled for maps or not (so I might stick it somewhere else)

}

} // namespace
inline void mergeYamlMaps(YAML::Node& a, const YAML::Node& b, MergeMode mode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I don't have the header for this present right now but might be good to specify in the docstring that the MergeMode will be superseded by tags in the config (Which makes sense, just might be good to be clear about that). Maybe can call it default_mode or so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the sequence version actually aren't declared in the header (they're meant to be internal helper functions, so the default mode comes from the publicly accessible mergeYamlNodes). But will document more of the behavior for the public function

}

inline void mergeYamlSequences(YAML::Node& a, const YAML::Node& b, MergeMode mode) {
const auto tag_mode = modeFromTag(b);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: same as before, maybe default_mode?

@GoldenZephyr
Copy link

Would it be possible to get a small, minimum viable example for how I'm supposed to run the commandline compositor (with e.g., two yaml files and simple tag interpolation)?

@nathanhhughes
Copy link
Collaborator Author

Would it be possible to get a small, minimum viable example for how I'm supposed to run the commandline compositor

At some point yes, though this is what I was going to use in the meantime until the interpolation / substitution parsing is actually stable and we've tested the compositing more

@nathanhhughes nathanhhughes merged commit 2f5186b into main Apr 30, 2025
2 checks passed
@nathanhhughes nathanhhughes deleted the feature/control_append branch April 30, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants