#!/usr/bin/env python
from __future__ import print_function

import argparse, sys
from chokola import *

__version__ = '0.2.0'
__program__ = 'chokola'

def main(args):

    if args.version:
        print('{0} {1}\nPython {2}'.format(__program__, __version__, sys.version))
        raise SystemExit

    call(args.source, args.type, args.table_classes, args.tr_classes, args.th_classes, args.td_classes)

if __name__ == '__main__':

    try:
        parser = argparse.ArgumentParser(prog=__program__, add_help=False)
        parser.add_argument('source', help='YAML file.', nargs='?')
        parser.add_argument('type', help='The type of the output.', nargs='?', choices=['markdown', 'html', 'latex'], default='html')
        parser.add_argument('-v', '--version', help='Show program\'s version number and exit.', action='store_true')
        parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, help='Show this help message and exit.')
        parser.add_argument('--table-classes', help='Add class to table.', nargs='*')
        parser.add_argument('--tr-classes', help='Add class to tr.', nargs='*')
        parser.add_argument('--th-classes', help='Add class to th.', nargs='*')
        parser.add_argument('--td-classes', help='Add class to td.', nargs='*')
        args = parser.parse_args()

        main(args)

    except RuntimeError as e:
        print(e)

    except (KeyboardInterrupt, SystemExit):
        pass
