#!/usr/bin/env python

from canari.commands.common import get_commands
from argparse import ArgumentParser


__author__ = 'Nadeem Douba'
__copyright__ = 'Copyright 2012, Canari Project'
__credits__ = []

__license__ = 'GPL'
__version__ = '0.1'
__maintainer__ = 'Nadeem Douba'
__email__ = 'ndouba@gmail.com'
__status__ = 'Development'



cmds = get_commands()


def parse_args():
    parser = ArgumentParser(
        description='Centralized Canari Management System',
        add_help=False
    )
    parser.add_argument(
        'command',
        metavar='<command>',
        choices=cmds,
        default='help',
        nargs='?',
        help='The name of the command you wish to run (%s).' % ', '.join(cmds),
    )
    args = parser.parse_known_args()
    return args


def main():
    args = parse_args()
    cmds[args[0].command].run(args[1])


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('exiting...')
        pass