mattrobenolt / jinja2-cli

CLI for Jinja2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotenv support

razvanphp opened this issue · comments

After I struggled some time to get the ini parser to work, I realised there is no possibility to use dotenv format, that is, ini files without sections, or exactly the output of env bash command.

This would actually allow something like env |jinja2 helloworld.tmpl --format=ini, that brings environment support more close to j2cli project.

I had to dig in closed github issues to find out about environ() trick (which is undocumented also) and I personally find hacky, since it requires special jinja templates, not sharable with ansible for example.

Thank you for your time!

Yeah, ini doesn't really overlap with env files. env files are much less structured and in lots of cases don't even need to be parsed since their format allows them to be directly set into env.

I'd be down for supporting an env format.

@razvanphp mind commenting on #39? Would that help you out? That adds a --format=env.

Looks... simple, I'm not proficient in python tho.

My only concern is about the strictness of the input file quality, for example what if there are spaces between =, value and/or key, inline comments, and most importantly, special characters in either of the sides.

I used successfully until now crudini tool, also written in python, maybe it can be a good inspiration. You can also check the example.ini file for some easy-to-add tests.

Thank you again for your readiness!

Oh, right. I should handle empty lines and commented lines. I tested with my env as input and things were fine. Will handle the other cases.

I've addressed empty lines and commented lines. Are there any other cases? fwiw crudini is an entirely different thing. That's specifically for ini files. What you're suggesting here is a format that is standard, called envfile.

Which is consumed by several tools already, notably docker. The format is specifically designed for environment variables and not intended to replace or even relate to ini files.

See https://github.com/docker/docker/blob/master/runconfig/opts/envfile.go#L26 for Docker's parsing of this file.

Ok, fair enough, LGTM then.

Please add the documentation tho, I know I struggled because of lack of examples.

Any idea when this would reach pip? I saw you already have 7.0-dev in works.