#!/usr/bin/env python

import sys
from getopt import getopt

from opscli.cli import Opscli
from opscli.debug import debug_enable

DEFAULT_SERVER = 'unix:/var/run/openvswitch/db.sock'
COMMAND_MODULE_PATHS = ("cli-commands", )


def usage():
    print "Usage: ops-cli [-h] [-s <server>] [-d <debug options>,...]"
    sys.exit()


def main(args):
    ovsdb_server = DEFAULT_SERVER
    opts, args = getopt(args, 'hs:d:')
    for opt, arg in opts:
        if opt == '-h':
            usage()
        elif opt == '-s':
            ovsdb_server = arg
        elif opt == '-d':
            for key in arg.split(','):
                debug_enable(key)
    try:
        cli = Opscli(ovsdb_server, command_module_paths=COMMAND_MODULE_PATHS)
        cli.start_shell()
    except Exception as e:
        # TODO log exception to debug log
        raise

if __name__ == '__main__':
    main(sys.argv[1:])
