From 557ac15f187fcefa616bf5d1833fa9f13f3937de Mon Sep 17 00:00:00 2001 From: Andras Kovi Date: Thu, 5 Dec 2024 14:15:12 +0100 Subject: [PATCH] Concretize Files.Glob documentation (#1314) Signed-off-by: Andras Kovi --- .../chart_template_guide/accessing_files.md | 29 ++++++++----------- .../chart_template_guide/builtin_objects.md | 6 ++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/content/en/docs/chart_template_guide/accessing_files.md b/content/en/docs/chart_template_guide/accessing_files.md index 33885abd4..4ca0bbb8e 100644 --- a/content/en/docs/chart_template_guide/accessing_files.md +++ b/content/en/docs/chart_template_guide/accessing_files.md @@ -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 }} ``` diff --git a/content/en/docs/chart_template_guide/builtin_objects.md b/content/en/docs/chart_template_guide/builtin_objects.md index 7372cc3b1..f6cc247c8 100644 --- a/content/en/docs/chart_template_guide/builtin_objects.md +++ b/content/en/docs/chart_template_guide/builtin_objects.md @@ -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.