commands.py 文件源码

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

项目:quantrocket-client 作者: quantrocket-llc 项目源码 文件源码
def main():
    parser = get_parser()
    if sys.stdin.isatty():
        try:
            import argcomplete
        except ImportError:
            pass
        else:
            argcomplete.autocomplete(parser)
    args = parser.parse_args()
    args = vars(args)
    args.pop("command")
    args.pop("subcommand", None)
    func_name = args.pop("func")
    func = import_func(func_name)
    try:
        result, exit_code = func(**args)
    except:
        if not sys.stdin.isatty():
            import traceback
            msg = traceback.format_exc()
            handle_error(msg)
        raise
    else:
        if result:
            # nonzero exit codes for non-interactive commands should be
            # logged
            if exit_code > 0 and not sys.stdin.isatty() and not sys.stdout.isatty():
                handle_error(result)
            # otherwise print
            else:
                print(result)

        return exit_code
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号