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
55$ cat data.json | jinja2 helloworld.tmpl
66$ curl -s http://httpbin.org/ip | jinja2 helloip.tmpl
77$ curl -s http://httpbin.org/ip | jinja2 helloip.tmpl > helloip.html
8+ $ JINJA_INPUT_DATA_PATH=payload.json jinja2 helloworld.tmpl
89```
910
1011## Install
@@ -28,6 +29,15 @@ Options:
2829 template
2930```
3031
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+
3141## Optional YAML support
3242If ` PyYAML ` is present, you can use YAML as an input data source.
3343
Original file line number Diff line number Diff line change @@ -291,7 +291,7 @@ def is_fd_alive(fd):
291291def cli (opts , args ):
292292 template_path , data = args
293293 format = opts .format
294- if data in ("-" , "" ):
294+ if data in ("-" , "" ) and not "JINJA_INPUT_DATA_PATH" in os . environ :
295295 if data == "-" or (data == "" and is_fd_alive (sys .stdin )):
296296 data = sys .stdin .read ()
297297 if format == "auto" :
@@ -302,7 +302,7 @@ def cli(opts, args):
302302 else :
303303 format = "json"
304304 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 ))
306306 if format == "auto" :
307307 ext = os .path .splitext (path )[1 ][1 :]
308308 if has_format (ext ):
You can’t perform that action at this time.
0 commit comments