Skip to content

Commit

Permalink
Merge pull request #125 from projectsyn/value_default
Browse files Browse the repository at this point in the history
Add getValueOrDefault helper
  • Loading branch information
corvus-ch authored Jun 30, 2020
2 parents fee955a + 2149091 commit 5840f34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions commodore/lib/commodore.libjsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -133,4 +143,5 @@ local envList(map) = [
addNamespaceToHelmOutput: addNamespaceToHelmOutput,
proxyVars: proxyVars,
envList: envList,
getValueOrDefault: getValueOrDefault,
}

0 comments on commit 5840f34

Please sign in to comment.