-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Conversation
4f655be
to
9e57622
Compare
$ 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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't tried...
There was a problem hiding this comment.
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...
9e57622
to
9174c04
Compare
Signed-off-by: Dave Henderson <[email protected]>
9174c04
to
15cd750
Compare
Fixes #310
Signed-off-by: Dave Henderson [email protected]