#!/usr/bin/env python
from jinja2 import Template, Environment, FileSystemLoader
import os,sys

def arg_parse():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('template')
    parser.add_argument('-i', '--inputdir', default='/template')
    parser.add_argument('-o', '--output', default='')
    return parser.parse_args()

def main():

    args = arg_parse()

    env = Environment(loader=FileSystemLoader(args.inputdir))
    template = env.get_template(args.template)
    disp_text = template.render(os.environ)

    if args.output == '':
        print(disp_text)
    else:
        path_w = args.output
        with open(path_w, mode='w') as f:
            f.write(disp_text)

if __name__ == '__main__':
    main()
