Skip to content

Commit 2da1fcc

Browse files
Library 2.2.5 (#38)
1 parent 4f4ccc9 commit 2da1fcc

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

charts/library/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: library
33
description: Buttahtoast Helm Library
44
type: library
5-
version: 2.2.4
5+
version: 2.2.5
66
appVersion: 0.1.0
77
home: https://github.com/buttahtoast/helm-charts/tree/master/charts/library
88
icon: "https://avatars0.githubusercontent.com/u/67652090?s=400&u=874d1c989b0afc2789865be01051f0bbfc84ae32&v=4"
@@ -19,5 +19,5 @@ sources:
1919
annotations:
2020
artifacthub.io/containsSecurityUpdates: "false"
2121
artifacthub.io/changes: |
22-
- "[Fixed]: Types Function `lib.utils.types.validate` Allows false as default value"
22+
- "[Added]: Added Function `lib.utils.dicts.unset"
2323
artifacthub.io/prerelease: "false"

charts/library/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Buttahtoast Library
22

3-
![Version: 2.2.4](https://img.shields.io/badge/Version-2.2.4-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square)
3+
![Version: 2.2.5](https://img.shields.io/badge/Version-2.2.5-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square)
44

55
This is our take on a library Chart. It contains simple functions which are (will be) used across all of our charts. Feel free the add or improve the existing templates. This Chart is still under development/testing. Feel free to use it, if you find any issues with it, please create an issue/PR. We will try to get bugs fixed as soon as possible!
66

@@ -922,6 +922,28 @@ result:
922922
- C
923923
```
924924

925+
### Unset
926+
---
927+
928+
Unset a key by path in a dictionary
929+
930+
#### Arguments
931+
932+
If an as required marked argument is missing, the template engine will fail intentionally.
933+
934+
* `.path` - The key path
935+
* `.data` - The dictionary to lookup
936+
937+
#### Returns
938+
939+
Directly removes key on dictionary, no return
940+
941+
#### Usage:
942+
943+
```
944+
{- include "lib.utils.dicts.unset" (dict "path" "sub.key" "data" (dict "sub" (dict "key" (list "A" "B" "C")))) }
945+
```
946+
925947
## [Extras](./templates/utils/_extras.tpl)
926948

927949
### Environment

charts/library/README.md.gotmpl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,28 @@ result:
928928
- C
929929
```
930930

931+
### Unset
932+
---
933+
934+
Unset a key by path in a dictionary
935+
936+
#### Arguments
937+
938+
If an as required marked argument is missing, the template engine will fail intentionally.
939+
940+
* `.path` - The key path
941+
* `.data` - The dictionary to lookup
942+
943+
#### Returns
944+
945+
Directly removes key on dictionary, no return
946+
947+
#### Usage:
948+
949+
```
950+
{- include "lib.utils.dicts.unset" (dict "path" "sub.key" "data" (dict "sub" (dict "key" (list "A" "B" "C")))) }
951+
```
952+
931953
## [Extras](./templates/utils/_extras.tpl)
932954

933955
### Environment

charts/library/templates/utils/_dicts.tpl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,26 @@
5959
{{- else -}}
6060
{{- printf "%s" (toYaml $result) -}}
6161
{{- end -}}
62-
{{- end -}}
62+
{{- end -}}
63+
64+
65+
{{/*
66+
Unset <Template>
67+
*/}}
68+
{{- define "lib.utils.dicts.unset" -}}
69+
{{- $path := trimAll "." $.path -}}
70+
{{- if and $path $.data -}}
71+
{{- $buf := $.data -}}
72+
{{- $paths := (splitList "." $path) -}}
73+
{{- range $i, $p := $paths -}}
74+
{{- if (hasKey $buf .) }}
75+
{{- if eq (last $paths) . -}}
76+
{{- $_ := unset $buf . -}}
77+
{{- else -}}
78+
{{- $buf = get $buf . -}}
79+
{{- end -}}
80+
{{- end -}}
81+
{{- end -}}
82+
{{- end -}}
83+
{{- end -}}
84+

0 commit comments

Comments
 (0)