#!python

import argparse

from podop import run_server, SERVER_TYPES, TABLE_TYPES


def main():
    """ Run a podop server based on CLI arguments
    """
    parser = argparse.ArgumentParser("Postfix and Dovecot proxy")
    parser.add_argument("--socket", required=True,
                        help="path to the listening unix socket")
    parser.add_argument("--mode", choices=SERVER_TYPES.keys(), required=True,
                        help="select which server will connect to Podop")
    parser.add_argument("--name", action="append",
                        help="name of each configured table")
    parser.add_argument("--type", choices=TABLE_TYPES.keys(), action="append",
                        help="type of each configured table")
    parser.add_argument("--param", action="append",
                        help="mandatory param for each table configured")
    parser.add_argument("-v", "--verbose", dest="verbosity",
                        action="count", default=0,
                        help="increases log verbosity for each occurence.")
    args = parser.parse_args()
    run_server(
        args.verbosity, args.mode, args.socket,
        zip(args.name, args.type, args.param) if args.name else []
    )


if __name__ == "__main__":
    main()
