#!/usr/bin/env python3
# uguu - generate Flexget config files.
#
# Author: slowpoke <mail+git@slowpoke.io>
#
# This program is free software under the non-terms
# of the Anti-License. Do whatever the fuck you want.
#
# Github: https://www.github.com/proxypoke/uguu
# (Shortlink: https://git.io/uguu)
#
# Format options for vim. Please adhere to them.
# vim: set et ts=4 sw=4 tw=80:

import argparse
import os
import yaml

import uguu

__version__ = uguu.__version__


def main():
    parser = argparse.ArgumentParser(
        description="generate Flexget config files")

    parser.add_argument(
        '-c', '--config', metavar='CONFIG', dest='uguu',
        default='~/.uguu/config.yml', help='''path to the uguu configuration
        file (default: ~/.uguu/config.yml''')

    args = parser.parse_args()

    # check if the uguu config exists
    if not os.access(args.uguu, os.F_OK):
        print("Error: uguu config {0} does not exist.".format(args.uguu))
        exit(1)
    uguu_conf = uguu.read_config(args.uguu)
    print(yaml.dump(uguu.generate_config(uguu_conf)))
    exit(0)


if __name__ == "__main__":
    main()
