docopt2.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:hadroid 作者: hadroid 项目源码 文件源码
def docopt_parse(doc, argv=None, version=None):
    import docopt as _docopt

    def extras_patch(help, version, options, doc):
        """Patch of docopt.extra handler.

        Patch for docopt's 'extras' function is needed, as it is hard
        sys-exiting the bot after '--help/-h' or '--version' commands
        """
        exc = None
        if help and any((o.name in ('-h', '--help')) and o.value
                        for o in options):
            exc = _docopt.DocoptExit()
            exc.args = (doc.strip("\n"), )
        if version and any(o.name == '--version' and o.value for o in options):
            exc = _docopt.DocoptExit()
            exc.args = (version, )
        if exc is not None:
            raise exc

    # Apply the patch above to docopt.extras
    _docopt.extras = extras_patch
    return _docopt.docopt(doc, argv=argv, version=version)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号