#!/usr/bin/env python
# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012  Björn Ricks <bjoern.ricks@googlemail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
# 02110-1301 USA

import sys
import os.path

from quilt.cli import find_command, list_commands

from quilt.error import QuiltError

def usage():
    print "%s command [--help] ..." % (os.path.basename(sys.argv[0]))
    print "Available commands:"
    for cmd in list_commands():
        print "\t", cmd[0]

def main():
    if not len(sys.argv) > 1:
        usage()
        sys.exit(1)

    cmd = sys.argv[1]
    args = sys.argv[2:]

    try:
        cmd_cls = find_command(cmd)
        if not cmd_cls:
            print "command %s not known." % cmd
            usage()
            sys.exit(2)
        cmd_cls().parse(args)
    except QuiltError, e:
        print e
        sys.exit(1)

if __name__ == "__main__":
        main()
