diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ae6a61..344bb457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ Please document all notable changes to this project in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Added + +* `getValueOrDefault` helper ([#125]) + ## [v0.1.6] ### Changed @@ -64,6 +69,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Initial implementation +[Unreleased]: https://github.com/projectsyn/commodore/compare/v0.1.6...HEAD [v0.1.0]: https://github.com/projectsyn/commodore/releases/tag/v0.1.0 [v0.1.1]: https://github.com/projectsyn/commodore/releases/tag/v0.1.1 [v0.1.2]: https://github.com/projectsyn/commodore/releases/tag/v0.1.2 @@ -82,3 +88,4 @@ Initial implementation [#100]: https://github.com/projectsyn/commodore/pull/100 [#103]: https://github.com/projectsyn/commodore/pull/103 [#106]: https://github.com/projectsyn/commodore/pull/106 +[#125]: https://github.com/projectsyn/commodore/pull/125 diff --git a/commodore/lib/commodore.libjsonnet b/commodore/lib/commodore.libjsonnet index 1686dd30..ea129d93 100644 --- a/commodore/lib/commodore.libjsonnet +++ b/commodore/lib/commodore.libjsonnet @@ -123,6 +123,16 @@ local envList(map) = [ for x in std.objectFields(map) ]; +/* + * \brief Helper to get a fields value or a default. + * + * \arg dict An arbitrary dictionary data structure. + * \arg field The name of a field. + * \arg default The value to return if the field is not present on the dict. + */ +local getValueOrDefault(dict, field, default) = + if std.objectHas(dict, field) then dict[field] else default; + { inventory: std.native('inventory'), yaml_load: std.native('yaml_load'), @@ -133,4 +143,5 @@ local envList(map) = [ addNamespaceToHelmOutput: addNamespaceToHelmOutput, proxyVars: proxyVars, envList: envList, + getValueOrDefault: getValueOrDefault, }