forked from ikhomyakov/pyaconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyaconf_render
executable file
·28 lines (23 loc) · 1.32 KB
/
pyaconf_render
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
import sys
import pyaconf
import argparse
try:
p = argparse.ArgumentParser()
p.add_argument('-if', '--input-format', nargs=1, type=str, default=['auto'], help='Input format: auto, pyaconf[.jinja2], yaml[.jinja2], json[.jinja2], ini[.jinja2]')
p.add_argument('-of', '--output-format', nargs=1, type=str, default=['yaml'], help='Output format: yaml or json')
p.add_argument('-c', '--context', nargs=1, type=str, default=[{}], help='Root level context config file (applied only to root level templates)')
p.add_argument('-cf', '--context-format', nargs=1, type=str, default=['auto'], help='Context format: auto, pyaconf[.jinja2], yaml[.jinja2], json[.jinja2], ini[.jinja2]')
p.add_argument('FILE', nargs='+', help='Config file in one of the following formats: pyaconf[.jinja2], yaml[.jinja2], json[.jinja2], ini[.jinja2]')
args = p.parse_args()
input_format = args.input_format[0]
output_format = args.output_format[0]
context_format = args.context_format[0]
context = args.context[0]
files = args.FILE
c = pyaconf.load(context, format=context_format, context={})
x = pyaconf.merge([pyaconf.load(src, format=input_format, context=c) for src in files])
pyaconf.dump(x, sys.stdout, format=output_format)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
#raise e