corn-config / corn

🌽 A simple and pain-free configuration language. Reference libcorn implementation and CLI.
https://cornlang.dev
MIT License
40 stars 5 forks source link

Support for deep object merging #30

Open JakeStanger opened 11 months ago

JakeStanger commented 11 months ago

Currently object merging only takes the immediate children into account.

There may be utility in changing this, or adding additional syntax, to perform a 'deep merge', running the merge against every child object.

Issue originates from the below discussion, which compares the feature to Nix's 'attrset merge':

Discussed in https://github.com/orgs/corn-config/discussions/29

Originally posted by **fbewivpjsbsby** November 6, 2023 1. What version of corn are you using? corn-cli 0.9.2 2. What is your operating system? Windows 10 ### Description It is like nixos module, config will merge when you imports config, [use ```//``` operators](https://ryantm.github.io/nixpkgs/functions/library/attrsets/#function-library-lib.attrsets.mergeAttrsList) or [use mkMerge](https://nixos.org/manual/nixos/stable/#sec-option-definitions-merging). Corn is override attrsets now. ### Steps to reproduce 1. Write this in corn file: ```corn let { $preferences_user_enable = { Value = true Status = "user" } // telemetry $policies_disable_telemetry = { DisableTelemetry = true DisableFirefoxStudies = true } // #TODO 'raw data' need git version corn // theme $policies_theme = { Preferences = { 'toolkit.legacyUserProfileCustomizations.stylesheets' = $preferences_user_enable 'layout.css.backdrop-filter.enabled' = $preferences_user_enable 'widget.non-native-theme.use-theme-accent' = $preferences_user_enable } } $policies_ech = { // ech need enable DNS over HTTPS DNSOverHTTPS = { Enabled = true ProviderURL = "https://1.1.1.1/dns-query" Locked = false ExcludedDomains = [""] } Preferences = { 'network.dns.echconfig.enabled' = $preferences_user_enable 'network.dns.http3_echconfig.enabled' = $preferences_user_enable } } } in { policies = { // telemetry ..$policies_disable_telemetry // ech ..$policies_ech // theme ..$policies_theme } } ``` 2. run ```corn [your corn file name].corn -t json``` It is override by $policies_theme: ```json { "policies": { "DisableTelemetry": true, "DisableFirefoxStudies": true, "DNSOverHTTPS": { "Enabled": true, "ProviderURL": "https://1.1.1.1/dns-query", "Locked": false, "ExcludedDomains": [ "" ] }, "Preferences": { "toolkit.legacyUserProfileCustomizations.stylesheets": { "Value": true, "Status": "user" }, "layout.css.backdrop-filter.enabled": { "Value": true, "Status": "user" }, "widget.non-native-theme.use-theme-accent": { "Value": true, "Status": "user" } } } } ```