Skip to content

feat: Add #insert directive for simple content inclusion#42

Draft
agonzalezrh wants to merge 8 commits intomasterfrom
pr-insert
Draft

feat: Add #insert directive for simple content inclusion#42
agonzalezrh wants to merge 8 commits intomasterfrom
pr-insert

Conversation

@agonzalezrh
Copy link

Summary

This PR adds a new directive that provides a clean way to include content without applying merge strategies.

Problem

Users needed a way to include content from other YAML files without the complex merge strategies that applies. The existing directive applies all merge strategies, which can be too aggressive for simple content inclusion.

Solution

Added a new directive that:

  • Includes content without applying merge strategies
  • Processes directives within inserted files
  • Performs selective merging for section (only and fields)
  • Uses simple overwrite for non- fields

Changes

  • includes.go: Added struct, function, and function
  • merge.go: Updated merge logic to handle directives with selective merging
  • merge_test.go: Added test case for parsing include directives with options

Usage

# Simple content inclusion without merge strategies
#insert /path/to/file.yaml

# Still works as before with merge strategies
#include /path/to/file.yaml

Benefits

  • Clean separation: vs are clearly different
  • Backward compatible: All existing directives continue to work
  • Simple and intuitive: means "just add this content"
  • Flexible: Processes includes within inserted files but without merge strategies

Testing

  • ✅ Preserves local values (asset_uuid, components)
  • ✅ Adds content from inserted files (sandboxes, deployer)
  • ✅ Processes #include directives within inserted files
  • ✅ Selective merging for meta section
  • ✅ Simple overwrite for other fields

- Add new #insert directive that includes content without merge strategies
- Implement parseInsert function to parse #insert directives
- Add getAllInserts function to collect insert directives recursively
- Update merge logic to handle #insert directives with selective merging
- For __meta__ section, only merge sandboxes and deployer fields
- For non-__meta__ fields, use simple overwrite
- Process #include directives within inserted files
- Add test case for parseInclude with options

This provides a cleaner alternative to complex merge strategies when you
want to simply add content without applying custom merge logic.
- Remove TestParseIncludeWithOptions and TestIncludeHasOption tests for notmerge
- Add TestParseInsert test for new #insert directive functionality
- Clean up test file to focus on current #insert implementation
- Preserve critical fields: asset_uuid, components, catalog, anarchy, ansible_control_plane, ansible_controller_select_mode, ansible_controllers
- Allow merging of sandboxes and deployer fields from insert
- Special handling for deployer section to merge sub-fields (like execution_environment)
- Maintains local values while adding content from inserted files

This ensures that #insert adds content without overwriting critical local configuration.
- Only add fields that don't already exist in local configuration
- Preserve all local variables and __meta__ fields
- Add new content from insert without overwriting existing values
- Much simpler and cleaner implementation

This ensures #insert truly just adds content without any overwrites.
- Remove all complex preservation logic
- Just add all content from insert files
- Simple and straightforward approach
- Processes includes within inserted files correctly
- Just include the content of the insert file
- No complex merging or preservation logic
- Simple and straightforward approach
- Works correctly without schema validation errors
- Process includes within inserted files correctly
- Preserve local variables like asset_uuid and components
- Only add new __meta__ fields that don't already exist
- Add non-__meta__ fields only if they don't exist
- Tested and working correctly
- Removes unused function that was causing linter error
- Clean up code
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.

1 participant