usage.py 文件源码

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

项目:rcli 作者: contains-io 项目源码 文件源码
def parse_commands(docstring):
    # type: (str) -> Generator[Tuple[List[str], List[str]], None, None]
    """Parse a docopt-style string for commands and subcommands.

    Args:
        docstring: A docopt-style string to parse. If the string is not a valid
            docopt-style string, it will not yield and values.

    Yields:
        All tuples of commands and subcommands found in the docopt docstring.
    """
    try:
        docopt.docopt(docstring, argv=())
    except (TypeError, docopt.DocoptLanguageError):
        return
    except docopt.DocoptExit:
        pass
    for command in _parse_section('usage', docstring):
        args = command.split()
        commands = []
        i = 0
        for i, arg in enumerate(args):
            if arg[0].isalpha() and not arg[0].isupper():
                commands.append(arg)
            else:
                break
        yield commands, args[i:]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号