Merge pull request #42 from atomicptr/fix/env-stdin

Fix not being able to use the env format with stdin
This commit is contained in:
Mark 2019-07-18 17:59:35 +03:00 committed by GitHub
commit d3d78db8ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 3 deletions

View File

@ -177,7 +177,7 @@ NGINX_LOGS=/var/log/nginx/
And render with:
$ j2 config.j2 data.env
$ env | j2 --format=env config.j2.
$ env | j2 --format=env config.j2
This is especially useful with Docker to link containers together.

View File

@ -138,7 +138,7 @@ def render_command(cwd, environ, stdin, argv):
}[os.path.splitext(args.data)[1]]
# Input: data
if args.data == '-' and args.format == 'env':
if args.data == '-' and args.format == 'env' and (stdin is None or stdin.isatty()):
input_data_f = None
else:
input_data_f = stdin if args.data == '-' else open(args.data)

View File

@ -113,7 +113,7 @@ def _parse_env(data_string):
And render with:
$ j2 config.j2 data.env
$ env | j2 --format=env config.j2.
$ env | j2 --format=env config.j2
This is especially useful with Docker to link containers together.
"""

View File

@ -98,6 +98,8 @@ class RenderTest(unittest.TestCase):
self._testme_std(['resources/nginx-env.j2', 'resources/data.env'])
# Format
self._testme_std(['--format=env', 'resources/nginx-env.j2', 'resources/data.env'])
# Stdin
self._testme_std(['--format=env', 'resources/nginx-env.j2'], stdin=open('resources/data.env'))
# Environment!
env = dict(NGINX_HOSTNAME='localhost', NGINX_WEBROOT='/var/www/project', NGINX_LOGS='/var/log/nginx/')