#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""txt2pdf - Markdown to PDF conversion tool.

Usage: txt2pdf [options] INPUT.MD OUTPUT.PDF

Options:
    --css=STYLE.CSS
    --header=HEADER.HTML
    --footer=FOOTER.HTML
    --html-to-stdout
"""
import os
import sys

from docopt import docopt
from txt2pdf import __version__
from txt2pdf.core import txt2pdf


def main(argv=None):

    # Parse command line arguments
    arguments = docopt(
        __doc__,
        version='txt2pdf %s' % __version__
    )

    # Paths
    md_file_path = arguments.get('INPUT.MD')
    pdf_file_path = arguments.get('OUTPUT.PDF')
    css_file_path = arguments.get('--css', None)
    header_file_path = arguments.get('--header', None)
    footer_file_path = arguments.get('--footer', None)
    print_html_to_stdout = arguments.get('--html-to-stdout', False)
    base_url = os.getcwd()

    txt2pdf(pdf_file_path,
           md_file_path=md_file_path,
           css_file_path=css_file_path,
           header_file_path=header_file_path,
           footer_file_path=footer_file_path,
           print_html_to_stdout=print_html_to_stdout,
           base_url=base_url)

    return 0


if __name__ == '__main__':
    sys.exit(main())
