wrouesnel / p2cli

pongo2 cli - like the j2cli package in python, but compiles to self-contained go executables
GNU General Public License v2.0
87 stars 19 forks source link

return non-zero for missing input values #15

Closed shantanugadgil closed 3 years ago

shantanugadgil commented 4 years ago

can p2cli be made to return non-zero if there are missing input values?

right now it seems to return 0 even if input values are missing.

❯ p2 --template example.tpl --input example.vars.json --format json
Hello, my name is
❯  echo $?
0
❯ cat example.tpl
Hello, my name is {{ name }}
❯ cat example.vars.json
{
    "foo": "bar"
}
wrouesnel commented 3 years ago

This isn't really possible while still supporting environment variables where that's important. If json structure is important, really you need to validate your own schema before feeding to the template.

In a practical sense: p2 doesn't give me any options to detect this AFAIK, so otherwise a flag would be possible.

shantanugadgil commented 3 years ago

I was hoping p2 has something equivalent of jinja2's equivalent of "error if variable is unset"