From 8ae2a9cafc53303c701f77d4ab91e3574464ab72 Mon Sep 17 00:00:00 2001 From: Christopher Kaster Date: Tue, 2 Jul 2019 14:11:20 +0200 Subject: [PATCH] fix not being able to use format env with stdin --- README.md | 2 +- j2cli/cli.py | 2 +- j2cli/context.py | 2 +- tests/render-test.py | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 77abdf2..5461a8a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/j2cli/cli.py b/j2cli/cli.py index 10a39d8..883ec73 100644 --- a/j2cli/cli.py +++ b/j2cli/cli.py @@ -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) diff --git a/j2cli/context.py b/j2cli/context.py index e444eda..2b14bc8 100644 --- a/j2cli/context.py +++ b/j2cli/context.py @@ -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. """ diff --git a/tests/render-test.py b/tests/render-test.py index 9824ae3..d0f44f4 100644 --- a/tests/render-test.py +++ b/tests/render-test.py @@ -98,6 +98,8 @@ def test_env(self): 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/')