import getopt

import sys

from dumper import DirectAdminDumper
from utils import write_yaml


def print_usage():
    print(
        '''Usage: directadmin-hosting-description.py [OPTIONS]...
    -f, --file          output filename
Example:
    directadmin-hosting-description.py -f myserver.yaml'''
    )


def get_options():
    """
    :rtype: dict 
    """
    options = {
        "file": "hosting-description.yaml"
    }
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help", "file="])
    except getopt.GetoptError:
        print_usage()
        sys.exit(1)
    for opt, arg in opts:
        if opt in ("-h", '--help'):
            print_usage()
            sys.exit()
        elif opt in ("-f", "--file"):
            options["file"] = arg
    return options


if __name__ == "__main__":
    config = get_options()
    directadmin_dump = DirectAdminDumper().create_dump()
    write_yaml(config["file"], directadmin_dump)
