File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ $ jinja2 helloworld.tmpl data.json --format=json
5
5
$ cat data.json | jinja2 helloworld.tmpl
6
6
$ curl -s http://httpbin.org/ip | jinja2 helloip.tmpl
7
7
$ curl -s http://httpbin.org/ip | jinja2 helloip.tmpl > helloip.html
8
+ $ JINJA_INPUT_DATA_PATH=payload.json jinja2 helloworld.tmpl
8
9
```
9
10
10
11
## Install
@@ -28,6 +29,15 @@ Options:
28
29
template
29
30
```
30
31
32
+ ## Reading input data path from environment variable
33
+
34
+ Set the value of the environment variable ` JINJA_INPUT_DATA_PATH ` to the path to your input data.
35
+ This way the input data get read from there and you don't have to specify it on the command line:
36
+
37
+ ```
38
+ JINJA_INPUT_DATA_PATH=payload.json jinja2 helloworld.tmpl
39
+ ```
40
+
31
41
## Optional YAML support
32
42
If ` PyYAML ` is present, you can use YAML as an input data source.
33
43
Original file line number Diff line number Diff line change @@ -291,7 +291,7 @@ def is_fd_alive(fd):
291
291
def cli (opts , args ):
292
292
template_path , data = args
293
293
format = opts .format
294
- if data in ("-" , "" ):
294
+ if data in ("-" , "" ) and not "JINJA_INPUT_DATA_PATH" in os . environ :
295
295
if data == "-" or (data == "" and is_fd_alive (sys .stdin )):
296
296
data = sys .stdin .read ()
297
297
if format == "auto" :
@@ -302,7 +302,7 @@ def cli(opts, args):
302
302
else :
303
303
format = "json"
304
304
else :
305
- path = os .path .join (os .getcwd (), os .path .expanduser (data ))
305
+ path = os .path .join (os .environ [ "JINJA_INPUT_DATA_PATH" ]) if "JINJA_INPUT_DATA_PATH" in os . environ else os . path . join ( os . getcwd (), os .path .expanduser (data ))
306
306
if format == "auto" :
307
307
ext = os .path .splitext (path )[1 ][1 :]
308
308
if has_format (ext ):
You can’t perform that action at this time.
0 commit comments