def add_subcommands(parser, commands):
    """Add commands to a parser"""
    subps = parser.add_subparsers()
    for cmd, cls in commands:
        subp = subps.add_parser(cmd, help=cls.__doc__)
        add_args = getattr(cls, 'add_arguments', None)
        if add_args:
            add_args(subp)
        handler = getattr(cls, 'handle', None)
        if handler:
            subp.set_defaults(handler=handler)
