Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test.Required function #392

Merged
merged 1 commit into from
Sep 8, 2018
Merged

Add test.Required function #392

merged 1 commit into from
Sep 8, 2018

Conversation

hairyhenderson
Copy link
Owner

Fixes #310

Signed-off-by: Dave Henderson dhenderson@gmail.com

$ gomplate -d config=config.yaml -i '{{ (ds "config").empty | required "The `config` datasource must have a value defined for `empty`" }}'
template: <arg>:1:25: executing "<arg>" at <required "The `confi...>: error calling required: The `config` datasource must have a value defined for `empty`
$ gomplate -d config=config.yaml -i '{{ (ds "config").bogus | required "The `config` datasource must have a value defined for `bogus`" }}'
template: <arg>:1:7: executing "<arg>" at <"config">: map has no entry for key "bogus"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we could do something like:

{{ (ds "config") | get "bogus" | required "The `config` datasource must have a value defined for `bogus`"

where get works like getenv and does not error?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't tried...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that might work. There is the index built-in, but it doesn't pipeline so well:

$  bin/gomplate -i '{{ $j := (json `{"foo":"bar"}`)}}{{ index $j "baz" | required "nope!" }}'
template: <arg>:1:53: executing "<arg>" at <required "nope!">: error calling required: nope!

if only index took arguments the other way around, it'd be a simple case of {{ $j | index "baz" | required "nope!" }}.

I could write an alternate for index that takes arguments in the opposite order for easier pipelining, but it may not be that necessary...

Signed-off-by: Dave Henderson <dhenderson@gmail.com>
@hairyhenderson hairyhenderson changed the title [WIP] Add test.Required function Add test.Required function Sep 8, 2018
@hairyhenderson hairyhenderson merged commit 2feda27 into master Sep 8, 2018
@hairyhenderson hairyhenderson deleted the add-required-func branch September 8, 2018 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants