#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
yaml2rst – A Simple Tool for Documenting YML Files
"""
#
# Copyright 2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from __future__ import print_function

__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
__copyright__ = "Copyright 2015 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
__version__ = "0.1"


import yaml2rst
import argparse
import sys

def main(infilename, outfilename):
    if infilename == '-':
        infh = sys.stdin
    else:
        infh = open(infilename)
    if outfilename == '-':
        outfh = sys.stdout
    else:
        outfh = open(outfilename, "w")
    for l in yaml2rst.convert(infh.readlines()):
        print(l.rstrip(), file=outfh)


parser = argparse.ArgumentParser()
parser.add_argument('infilename', metavar='infile',
                    help="YAML-file to read (`-` for stdin)")
parser.add_argument('outfilename', metavar='outfile',
                    help="rst-file to write (`-` for stdout)")
args = parser.parse_args()
main(**vars(args))

