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

Concretize Files.Glob documentation #1664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 12 additions & 17 deletions content/en/docs/chart_template_guide/accessing_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,40 +125,35 @@ The imported functions are:
## Glob patterns

As your chart grows, you may find you have a greater need to organize your files
more, and so we provide a `Files.Glob(pattern string)` method to assist in
more, and so we provide the `.Files.Glob(pattern string)` method to assist in
extracting certain files with all the flexibility of [glob
patterns](https://godoc.org/github.com/gobwas/glob).

`.Glob` returns a `Files` type, so you may call any of the `Files` methods on
the returned object.

For example, imagine the directory structure:
For example, to return all Yaml files from all available directories, you have
multiple options with Glob:

```
foo/:
foo.txt foo.yaml

bar/:
bar.go bar.conf baz.yaml
```yaml
{{ range $path, $_ := .Files.Glob "**.yaml" }}
{{ .Get $path }}
{{ end }}
```

You have multiple options with Globs:

Or

```yaml
{{ $currentScope := .}}
{{ range $path, $_ := .Files.Glob "**.yaml" }}
{{- with $currentScope}}
{{ .Files.Get $path }}
{{- end }}
{{ range $path, $content := .Files.Glob "**.yaml" }}
{{ $content | toString }}
{{ end }}
```

Or

```yaml
{{ range $path, $_ := .Files.Glob "**.yaml" }}
{{ $.Files.Get $path }}
{{ range .Files.Glob "**.yaml" }}
{{ . | toString }}
{{ end }}
```

Expand Down
6 changes: 3 additions & 3 deletions content/en/docs/chart_template_guide/builtin_objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ access in your templates.
cannot use it to access templates, you can use it to access other files in the
chart. See the section [Accessing Files]({{< ref
"/docs/chart_template_guide/accessing_files.md" >}}) for more.
- `Files.Get` is a function for getting a file by name (`.Files.Get
- `Files.Get` is a function that returns the file contents as string (`.Files.Get
config.ini`)
- `Files.GetBytes` is a function for getting the contents of a file as an
- `Files.GetBytes` is a function that returns the contents of a file as an
array of bytes instead of as a string. This is useful for things like
images.
- `Files.Glob` is a function that returns a list of files whose names match
- `Files.Glob` is a function that returns a list of file path, content bytes tuples whose names match
the given shell glob pattern.
- `Files.Lines` is a function that reads a file line-by-line. This is useful
for iterating over each line in a file.
Expand Down