import cmdparse
import commands
import logging
import optparse
import sys

parser = cmdparse.CommandParser()
parser.add_option("", "--debug", action="store_true",
                  help=optparse.SUPPRESS_HELP)
parser.add_option("", "--profile", action="store_true",
                  help=optparse.SUPPRESS_HELP)

parser.add_commands(commands)

def main():
    (command, options, args) = parser.parse_args()

    formatter = logging.Formatter("%(levelname)s: %(message)s")
    console = logging.StreamHandler()
    console.setFormatter(formatter)
    logging.root.addHandler(console)

    if options.debug:
        logging.root.setLevel(logging.DEBUG)
    else:
        logging.root.setLevel(logging.INFO)

    if options.profile:
        import cProfile

    if command is None:
        parser.print_help()
        sys.exit(1)

    try:
        if options.profile:
            cProfile.run("command.run(options, args)", "cobe.pstats")
        else:
            command.run(options, args)
    except KeyboardInterrupt:
        print
        sys.exit(1)

if __name__ == "__main__":
    main()

import cmdparse
import commands
import logging
import optparse
import sys

parser = cmdparse.CommandParser()
parser.add_option("", "--debug", action="store_true",
                  help=optparse.SUPPRESS_HELP)
parser.add_option("", "--profile", action="store_true",
                  help=optparse.SUPPRESS_HELP)

parser.add_command(commands.InitCommand(), "Control")
parser.add_command(commands.ConsoleCommand(), "Control")
parser.add_command(commands.LearnCommand(), "Learning")
parser.add_command(commands.LearnIrcLogCommand(), "Learning")

def main():
    (command, options, args) = parser.parse_args()

    formatter = logging.Formatter("%(levelname)s: %(message)s")
    console = logging.StreamHandler()
    console.setFormatter(formatter)
    logging.root.addHandler(console)

    if options.debug:
        logging.root.setLevel(logging.DEBUG)
    else:
        logging.root.setLevel(logging.INFO)

    if options.profile:
        import cProfile

    if command is None:
        parser.print_help()
        sys.exit(1)

    try:
        if options.profile:
            cProfile.run("command.run(options, args)", "cobe.pstats")
        else:
            command.run(options, args)
    except KeyboardInterrupt:
        print
        sys.exit(1)

if __name__ == "__main__":
    main()

Add command groups for better help output
Add command groups for better help output
