Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

* `getValueOrDefault` helper ([#125])
* `makeMergeable` helper ([#126])

## [v0.1.6]

Expand Down Expand Up @@ -89,3 +90,4 @@ Initial implementation
[#103]: https://github.com/projectsyn/commodore/pull/103
[#106]: https://github.com/projectsyn/commodore/pull/106
[#125]: https://github.com/projectsyn/commodore/pull/125
[#126]: https://github.com/projectsyn/commodore/pull/126
20 changes: 20 additions & 0 deletions commodore/lib/commodore.libjsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ local envList(map) = [
local getValueOrDefault(dict, field, default) =
if std.objectHas(dict, field) then dict[field] else default;

/*
* \brief makes an object deep mergeable
*
* Builds a new object from its input.
* All keys which contain an object will be suffixed with `+` in the result.
*
* \arg o An arbitrary object.
* \return The transformed object.
*/
local makeMergeable(o) = {
[key]+: makeMergeable(o[key])
for key in std.objectFields(o)
if std.isObject(o[key])
} + {
[key]: o[key]
for key in std.objectFields(o)
if !std.isObject(o[key])
};

{
inventory: std.native('inventory'),
yaml_load: std.native('yaml_load'),
Expand All @@ -144,4 +163,5 @@ local getValueOrDefault(dict, field, default) =
proxyVars: proxyVars,
envList: envList,
getValueOrDefault: getValueOrDefault,
makeMergeable: makeMergeable,
}