From cb5774a31d2ac883db87f27fe2942b8ea7975b70 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 24 Jan 2016 20:07:36 -0500 Subject: New datasource function - works for JSON files Signed-off-by: Dave Henderson --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index a625ddf3..81dc6734 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,22 @@ $ echo "Hello, {{.Env.USER}}" | gomplate Hello, hairyhenderson ``` +### Commandline Arguments + +#### `--datasource`/`-d` + +Add a data source in `name=URL` form. Specify multiple times to add multiple sources. The data can then be used by the [`datasource`](#datasource) function. + +A few different forms are valid: +- `mydata=file:///tmp/my/file.json` + - Create a data source named `mydata` which is read from `/tmp/my/file.json`. This form is valid for any file in any path. +- `mydata=file.json` + - Create a data source named `mydata` which is read from `file.json` (in the current working directory). This form is only valid for files in the current directory. +- `mydata.json` + - This form infers the name from the file name (without extension). Only valid for files in the current directory. + +## Syntax + #### About `.Env` You can easily access environment variables with `.Env`, but there's a catch: @@ -130,6 +146,31 @@ $ gomplate < input.tmpl Hello world ``` +#### `datasource` + +Parses a given datasource (provided by the [`--datasource/-d`](#--datasource-d) argument). + +Currently, only `file://` URLs are supported, and only the JSON format can be parsed. More support is coming. + +##### Example + +_`person.json`:_ +```json +{ + "name": "Dave" +} +``` + +_`input.tmpl`:_ +``` +Hello {{ (datasource "person").name }} +``` + +```console +$ gomplate -d person.json < input.tmpl +Hello Dave +``` + #### `ec2meta` Queries AWS [EC2 Instance Metadata](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for information. This only retrieves data in the `meta-data` path -- for data in the `dynamic` path use `ec2dynamic`. -- cgit v1.2.3