def _subcommand(group, *args, **kwargs):
    """Decorator to define a subcommand.

    This decorator is used for the group's @command decorator.
    """
    def decorator(f):
        if 'help' not in kwargs:
            kwargs['help'] = f.__doc__
        _parser_class = group._subparsers._parser_class
        if 'parser' in kwargs:
            # use a copy of the given parser
            group._subparsers._parser_class = _CopiedArgumentParser
        if 'parents' in kwargs:
            if not hasattr(f, '_argnames'):  # pragma: no cover
                f._argnames = []
            for p in kwargs['parents']:
                f._argnames += p._argnames if hasattr(p, '_argnames') else []
            kwargs['parents'] = [p.parser for p in kwargs['parents']]
        if args == ():
            f.parser = group._subparsers.add_parser(f.__name__, **kwargs)
        else:
            f.parser = group._subparsers.add_parser(*args, **kwargs)
        f.parser.set_defaults(**{'_func_' + group.__name__: f})
        f.climax = 'parser' not in kwargs
        group._subparsers._parser_class = _parser_class
        for arg in getattr(f, '_arguments', []):
            f.parser.add_argument(*arg[0], **arg[1])
        return f
    return decorator
def _subcommand ( group , * args , ** kwargs ) : def decorator ( f ) : if 'help' not in kwargs : kwargs [ 'help' ] = f . __doc__ _parser_class = group . _subparsers . _parser_class if 'parser' in kwargs : group . _subparsers . _parser_class = _CopiedArgumentParser if 'parents' in kwargs : if not hasattr ( f , '_argnames' ) : f . _argnames = [ ] for p in kwargs [ 'parents' ] : f . _argnames += p . _argnames if hasattr ( p , '_argnames' ) else [ ] kwargs [ 'parents' ] = [ p . parser for p in kwargs [ 'parents' ] ] if args == ( ) : f . parser = group . _subparsers . add_parser ( f . __name__ , ** kwargs ) else : f . parser = group . _subparsers . add_parser ( * args , ** kwargs ) f . parser . set_defaults ( ** { '_func_' + group . __name__ : f } ) f . climax = 'parser' not in kwargs group . _subparsers . _parser_class = _parser_class for arg in getattr ( f , '_arguments' , [ ] ) : f . parser . add_argument ( * arg [ 0 ] , ** arg [ 1 ] ) return f return decorator
Decorator to define a subcommand.

    This decorator is used for the group's @command decorator.