From 6056ca97d889fb268cc287334bc644e6b6d487d7 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Mon, 12 Nov 2018 23:22:06 -0500 Subject: New --context flag for adding datasources to context Signed-off-by: Dave Henderson --- docs/content/datasources.md | 6 ++++-- docs/content/syntax.md | 7 ++++--- docs/content/usage.md | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/content/datasources.md b/docs/content/datasources.md index 99e1dd58..e7dd5c9f 100644 --- a/docs/content/datasources.md +++ b/docs/content/datasources.md @@ -6,9 +6,9 @@ menu: main Datasources are an optional, but central concept in gomplate. While the basic flow of template rendering is taking an input template and rendering it into an output, there often is need to include data from one or more sources external to the template itself. -Some common use-cases include injecting sensitive material like passwords (which should not be stored in source-control with the templates), or providing simplified configuration formats that can be fed to a template to provide a much more complex output. +Some common use-cases include injecting sensitive material like passwords (which should not be stored unencrypted in source-control with the templates), or providing simplified configuration formats that can be fed to a template to provide a much more complex output. -Datasources can be defined with the [`--datasource`/`-d`][] command-line flag or the [`defineDatasource`][] function, and referenced via an _alias_ inside the template, using a function such as [`datasource`][] or [`include`][]. +Datasources can be defined with the [`--datasource`/`-d`][] command-line flag or the [`defineDatasource`][] function, and referenced via an _alias_ inside the template, using a function such as [`datasource`][] or [`include`][]. Datasources can additionally be loaded into the [context][] with the [`--context`/`-c`][] command-line flag. Since datasources are defined separately from the template, the same templates can be used with different datasources and even different datasource types. For example, gomplate could be run on a developer machine with a `file` datasource pointing to a JSON file containing test data, where the same template could be used in a production environment using a `consul` datasource with the real production data. @@ -432,6 +432,8 @@ $ gomplate -d vault=vault:///secret/foo -i '{{ (ds "vault").value }}' The file `/tmp/vault-aws-nonce` will be created if it didn't already exist, and further executions of `gomplate` can re-authenticate securely. [`--datasource`/`-d`]: ../usage/#datasource-d +[`--context`/`-c`]: ../usage/#context-c +[context]: ../syntax/#the-context [`--datasource-header`/`-H`]: ../usage/#datasource-header-h [`defineDatasource`]: ../functions/data/#definedatasource [`datasource`]: ../functions/data/#datasource diff --git a/docs/content/syntax.md b/docs/content/syntax.md index 57eacda9..c736c41b 100644 --- a/docs/content/syntax.md +++ b/docs/content/syntax.md @@ -133,9 +133,10 @@ $ gomplate -i '{{ with "foo" }}The context is {{ . }}{{ end }}' The context is foo ``` -Templates rendered by gomplate always have a _default_ context. In future, gomplate's -context may expand (_watch this space!_), but currently, it contains one item: the -system's environment variables, available as [`.Env`](#env). +Templates rendered by gomplate always have a _default_ context. You can populate +the default context from data sources with the [`--context`/`c`](../usage/#context-c) +flag. The special context item [`.Env`](#env) is available for referencing the +system's environment variables. ## Nested templates diff --git a/docs/content/usage.md b/docs/content/usage.md index 7e2dcdef..bdbc4249 100644 --- a/docs/content/usage.md +++ b/docs/content/usage.md @@ -77,6 +77,12 @@ A few different forms are valid: - `mydata.json` - This form infers the name from the file name (without extension). Only valid for files in the current directory. +### `--context`/`c` + +Add a data source in `name=URL` form, and make it available in the [default context][] as `.`. The special name `.` (period) can be used to override the entire default context. + +All other rules for the [`--datasource`/`-d`](#datasource-d) flag apply. + ### Overriding the template delimiters Sometimes it's necessary to override the default template delimiters (`{{`/`}}`). -- cgit v1.2.3