Skip to content

Commit 0b4b180

Browse files
committed
Adds AsMap to iterate over .Files.Glob
1 parent 7717a24 commit 0b4b180

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

example-charts/files-values/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ dataSecret:
4747
resource2.yaml: c29tZToKICByZXNvdXJjZTogImJsYWgyIg==
4848
```
4949

50+
File: Chart.yaml
51+
File: somefile.yaml
52+
File: templates/resource1.yaml
53+
File: templates/resource2.yaml
54+
File: values.yaml
55+
5056
## Values
5157

5258
| Key | Type | Default | Description |
@@ -61,5 +67,3 @@ dataSecret:
6167
| statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database |
6268
| statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database |
6369

64-
----------------------------------------------
65-
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)

example-charts/files-values/README.md.gotmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ dataSecret:
3939
{{ (.Files.Glob "templates/**.yaml").AsSecrets | indent 2 }}
4040
```
4141

42+
{{ range $path, $_ := (.Files.Glob "**.yaml").AsMap -}}
43+
File: {{$path}}
44+
{{ end }}
45+
4246
{{ template "chart.requirementsSection" . }}
4347

4448
{{ template "chart.valuesSection" . }}

pkg/document/files.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ func (f files) AsSecrets() string {
122122
return toYAML(m)
123123
}
124124

125+
func (f files) AsMap() map[string]*fileEntry {
126+
return f.foundFiles
127+
}
128+
125129
func (f files) Lines(path string) []string {
126130
if len(f.foundFiles) == 0 {
127131
return []string{}

pkg/document/files_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ func TestToSecret(t *testing.T) {
8383
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
8484
}
8585

86+
func TestToMap(t *testing.T) {
87+
as := assert.New(t)
88+
89+
f := getTestFiles()
90+
91+
out := f.Glob("ship/**").AsMap()
92+
as.Contains(out, "ship/captain.txt")
93+
as.Contains(out, "ship/stowaway.txt")
94+
as.NotContains(out, "story/name.txt")
95+
}
96+
8697
func TestLines(t *testing.T) {
8798
as := assert.New(t)
8899

0 commit comments

Comments
 (0)