Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from atomicptr/fix/env-stdin
Browse files Browse the repository at this point in the history
Fix not being able to use the env format with stdin
  • Loading branch information
kolypto authored Jul 18, 2019
2 parents a63336d + 8ae2a9c commit d3d78db
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion j2cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion j2cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/render-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down

0 comments on commit d3d78db

Please sign in to comment.