You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-x, --execute string a raw template to execute directly, without providing --file
21
-
-f, --file string the template file to process (required)
22
+
-v, --values string a file containing values to use for the template, a la Helm
23
+
--with-values automatically include a values.yaml file from the current working directory
24
+
-s, --strict strict mode: if an environment variable or value is used in the template but not set, it fails rendering
22
25
-h, --help help for tgen
23
-
-s, --strict enables strict mode: if an environment variable in the file is defined but not set, it'll fail
24
26
--version version for tgen
25
27
```
26
28
27
29
### Environment file
28
30
29
-
`tgen` supports an optional environment variable collection in a file but it's a pretty basic implementation of a simple key/value pair. The environment file works by finding lines that aren't empty or preceded by a pound `#` -- since they're treated as comments -- and then tries to find at least one equal (`=`) sign. If it can find at least one, all values on the left side of the equal sign become the key -- which is also uppercased so it's compatible with the `env` function defined above -- and the contents on the right side become the value. If the same line has more than one equal, only the first one is honored and all remaining ones become part of the value.
31
+
`tgen` supports an optional environment variable collection in a file but it's a pretty basic implementation of a simple key/value pair. The environment file works by finding lines that aren't empty or preceded by a pound `#` -- since they're treated as comments -- and then tries to find at least one equal (`=`) sign. If it can find at least one, all values on the left side of the equal sign become the key and the contents on the right side become the value. If the same line has more than one equal, only the first one is honored and all remaining ones become part of the value.
30
32
31
-
As an important note, environment variables found in the environment have preference over the environment file. That way, the environment file can define `A=1` but then the application can be run with `A=2 tgen [flags]` so it overrides `A` to the value of `2`.
33
+
There's no support for Bash interpolation or multiline values. If this is needed, consider using a YAML values file instead.
32
34
33
-
### Example
35
+
####Example
34
36
35
37
Consider the following template, named `template.txt`:
36
38
@@ -44,14 +46,14 @@ And the following environment file, named `contents.env`:
44
46
element=Oil
45
47
```
46
48
47
-
After being passed to `tgen` by executing `tgen -e contents.env -f template.txt`, the output becomes:
49
+
After being passed to `tgen`, the output becomes:
48
50
49
51
```bash
50
52
$ tgen -e contents.env -f template.txt
51
53
The dog licked the Oil and everyone laughed.
52
54
```
53
55
54
-
Using the inline mode to execute a template, you can also call `tgen -x '{{ env "element" }}' -e contents.env` (note the use of single-quotes since in Go, strings are always double-quoted) which will yield the same result:
56
+
Using the inline mode to execute a template, you can also call the program as such (note the use of single-quotes since in Go, strings are always double-quoted) which will yield the same result:
55
57
56
58
```bash
57
59
$ tgen -x '{{ env "element" }}' -e contents.env
@@ -60,7 +62,7 @@ The dog licked the Oil and everyone laughed.
60
62
61
63
Do note as well that using single quotes for the template allows you to prevent any bash special parsing logic that your terminal might have.
62
64
63
-
### Template Generation _a la Helm_
65
+
### Helm-style values
64
66
65
67
`tgen` can be used to generate templates, in a very similar way as `helm` can be used. However, do note that `tgen`'s intention is not to replace `helm` since it can't handle application lifecycle the way `helm` does, however, it can do a great job generating resources with very similar code.
Do keep in mind though your DevOps requirements in terms of keeping a copy of your YAML files, rendered. Additionally, the `readfile` function is akin to `helm`'s `.Files`, with the exception that **you can read any file the `tgen` binary has access**, including potentially sensitive files such as `/etc/passwd`. If this is a concern, please run `tgen` in a CI/CD environment or where access to these resources is limited.
131
133
134
+
You can also use a `values.yaml` file like Helm. `tgen` will allow you to read values from the values file as `.variable` or `.Values.variable`. The latter is the same as Helm's `.Values.variable` and the former is a shortcut to `.Values.variable` for convenience. Consider the following YAML values file:
135
+
136
+
```yaml
137
+
name: Patrick
138
+
```
139
+
140
+
And the following template:
141
+
142
+
```yaml
143
+
Hello, my name is {{ .name }}.
144
+
```
145
+
146
+
Running `tgen` with the values file will yield the following output:
147
+
148
+
```bash
149
+
$ tgen -f template.yaml -v values.yaml
150
+
Hello, my name is Patrick.
151
+
```
152
+
153
+
If your values file is called `values.yaml`, you also have the handy shortcut of simply specifying `--with-values` and `tgen` will automatically include the values file from the current working directory.
154
+
132
155
### Template functions
133
156
134
157
See [template functions](docs/functions.md) for a list of all the functions available.
root.Flags().StringVarP(&configs.environmentFile, "environment", "e", "", "an optional environment file to use (key=value formatted) to perform replacements")
35
-
root.Flags().StringVarP(&configs.templateFile, "file", "f", "", "the template file to process (required)")
38
+
root.Flags().StringVarP(&configs.templateFilePath, "file", "f", "", "the template file to process")
root.Flags().StringVarP(&configs.rawTemplate, "execute", "x", "", "a raw template to execute directly, without providing --file")
38
-
root.Flags().BoolVarP(&configs.stdin, "stdin", "i", false, "a stdin input to execute directly, without providing --file or --execute")
39
-
root.Flags().BoolVarP(&configs.strictMode, "strict", "s", false, "enables strict mode: if an environment variable in the file is defined but not set, it'll fail")
40
+
root.Flags().StringVarP(&configs.stdinTemplateFile, "execute", "x", "", "a raw template to execute directly, without providing --file")
41
+
root.Flags().StringVarP(&configs.valuesFile, "values", "v", "", "a file containing values to use for the template, a la Helm")
42
+
root.Flags().BoolVar(&withValues, "with-values", false, "automatically include a values.yaml file from the current working directory")
43
+
root.Flags().BoolVarP(&configs.strictMode, "strict", "s", false, "strict mode: if an environment variable or value is used in the template but not set, it fails rendering")
0 commit comments