dispatcher.py 文件源码

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

项目:rcli 作者: contains-io 项目源码 文件源码
def main():
    # type: () -> typing.Any
    """Parse the command line options and launch the requested command.

    If the command is 'help' then print the help message for the subcommand; if
    no subcommand is given, print the standard help message.
    """
    colorama.init(wrap=six.PY3)
    doc = usage.get_primary_command_usage()
    allow_subcommands = '<command>' in doc
    args = docopt(doc, version=settings.version,
                  options_first=allow_subcommands)
    if sys.excepthook is sys.__excepthook__:
        sys.excepthook = log.excepthook
    try:
        log.enable_logging(log.get_log_level(args))
        default_args = sys.argv[2 if args.get('<command>') else 1:]
        if (args.get('<command>') == 'help' and
                None not in settings.subcommands):
            subcommand = next(iter(args.get('<args>', default_args)), None)
            return usage.get_help_usage(subcommand)
        argv = [args.get('<command>')] + args.get('<args>', default_args)
        return _run_command(argv)
    except exc.InvalidCliValueError as e:
        return str(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号