Skip to content

Commit

Permalink
Concretize Files.Glob documentation (helm#1314)
Browse files Browse the repository at this point in the history
Signed-off-by: Andras Kovi <[email protected]>
  • Loading branch information
andraskoevi committed Dec 5, 2024
1 parent 62c6355 commit 557ac15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
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

0 comments on commit 557ac15

Please sign in to comment.