#!/usr/bin/env python3

from argparse import ArgumentParser
from traceback import print_exc

from risotto.machine import remove_cache, build_files, INSTALL_DIR


def main():
    parser = ArgumentParser()
    parser.add_argument('server_name', nargs='?')
    parser.add_argument('--nocache', action='store_true')
    parser.add_argument('--debug', action='store_true')
    parser.add_argument('--copy_tests', action='store_true')
    parser.add_argument('--template')
    args = parser.parse_args()
    if args.nocache:
        remove_cache()

    try:
        build_files(None,
                    args.server_name,
                    False,
                    args.copy_tests,
                    template=args.template,
                    )
    except Exception as err:
        if args.debug:
            print_exc()
        exit(err)
    print(f'templates generated in "{INSTALL_DIR}" directory')


main()