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

Adds AsMap to iterate over .Files.Glob #159

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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