A tool for embedding a file's contents into the template file.
The tool reads your input template file, loads pattern {{file "/file/want/embed"}}
, adds embedded content to the template file and writes to the output path.
- Load input file and replace
{{file "/path/to/another/file"}}
with content from/path/to/another/file
- Support both abolute path
{{file "/path/to/another/file"}}
and relative path{{file "./another/file"}}
- Support recursive embedded file. If embedded file content contains
{{file ""}}
, tool keep to load it.
Download the source code and try with:
go build -o output/config-template
Use config-template
Pull the docker image from:
docker pull ghcr.io/vnteamopen/config-template:main
- Create a file
person.yml
with following content:
person.yml
name: thuc
{{file "./bio.yml"}}
{{file "./secrets.yml"}}
- Create 2 files
bio.yml
andsecrets.yml
same folder withsecrets.yml
bio.yml
username: abc
password: xyz
secrets.yml
job: developer
interests: running
3.1. Run config-template
./config-template person.yml output.yml
or
config-template person.yml output.yml
3.2. Run config-template with docker
docker run --rm -it -v $(pwd):/files/ -w /files ghcr.io/vnteamopen/config-template:main /app/config-template ./person.yml ./output.yml
- output.yml will be write with content
name: thuc
username: abc
password: xyz
job: developer
interests: running
- Overwrite template file with
-w
flag
config-template -w person.yml
- Provide both flag
-w
andoutput.yml
will overwrite template file and write output file
config-template -w person.yml output.yml
- Provide multiple outputs
config-template person.yml output1.yml output2.yml
- Support output to stdout
config-template -out-screen person.yml
- Custom template's pattern
# change default pattern `{{file "path"}}` to `%%file "path"%%`
config-template -c %%,%% person.yml output.yml