Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getValueOrDefault helper #125

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 = function(dict, field, default)
corvus-ch marked this conversation as resolved.
Show resolved Hide resolved
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,
}