Skip to content

Commit

Permalink
Merge pull request #159 from terrycain/files_asmap
Browse files Browse the repository at this point in the history
Adds AsMap to iterate over .Files.Glob
  • Loading branch information
norwoodj authored Nov 2, 2023
2 parents 2743ca4 + 0b4b180 commit 3b87f0a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions example-charts/files-values/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ dataSecret:
resource2.yaml: c29tZToKICByZXNvdXJjZTogImJsYWgyIg==
```

File: Chart.yaml
File: somefile.yaml
File: templates/resource1.yaml
File: templates/resource2.yaml
File: values.yaml

## Values

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

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
4 changes: 4 additions & 0 deletions example-charts/files-values/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ dataSecret:
{{ (.Files.Glob "templates/**.yaml").AsSecrets | indent 2 }}
```

{{ range $path, $_ := (.Files.Glob "**.yaml").AsMap -}}
File: {{$path}}
{{ end }}

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}
Expand Down
4 changes: 4 additions & 0 deletions pkg/document/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (f files) AsSecrets() string {
return toYAML(m)
}

func (f files) AsMap() map[string]*fileEntry {
return f.foundFiles
}

func (f files) Lines(path string) []string {
if len(f.foundFiles) == 0 {
return []string{}
Expand Down
11 changes: 11 additions & 0 deletions pkg/document/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ func TestToSecret(t *testing.T) {
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
}

func TestToMap(t *testing.T) {
as := assert.New(t)

f := getTestFiles()

out := f.Glob("ship/**").AsMap()
as.Contains(out, "ship/captain.txt")
as.Contains(out, "ship/stowaway.txt")
as.NotContains(out, "story/name.txt")
}

func TestLines(t *testing.T) {
as := assert.New(t)

Expand Down

0 comments on commit 3b87f0a

Please sign in to comment.