cmd.py 文件源码

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

项目:axibot 作者: storborg 项目源码 文件源码
def main(args=sys.argv):
    p = argparse.ArgumentParser(description='Print with the AxiDraw.')
    p.add_argument('--verbose', action='store_true')
    p.add_argument('--mock', action='store_true')
    p.set_defaults(function=None)

    subparsers = p.add_subparsers(help='sub-command help')

    p_plan = subparsers.add_parser(
        'plan', help='Plan the plotting actions for an SVG file.')
    p_plan.add_argument('filename')
    p_plan.add_argument('--out')
    p_plan.add_argument('--overwrite', action='store_true')
    p_plan.set_defaults(function=plan)

    p_plot = subparsers.add_parser(
        'plot', help='Plot an SVG file directly.')
    p_plot.add_argument('filename')
    p_plot.set_defaults(function=plot)

    p_info = subparsers.add_parser(
        'info', help='Print information about an SVG file.')
    p_info.add_argument('filename')
    p_info.set_defaults(function=info)

    p_server = subparsers.add_parser(
        'server', help='Run a server for remote plotting.')
    p_server.add_argument('--port', type=int, default=8888)
    p_server.set_defaults(function=server)

    p_manual = subparsers.add_parser(
        'manual', help='Manual control shell.')
    p_manual.add_argument('cmd', nargs='*')
    p_manual.set_defaults(function=manual)

    opts, args = p.parse_known_args(args[1:])

    if coloredlogs:
        coloredlogs.install(level='DEBUG' if opts.verbose else 'INFO')
    else:
        logging.basicConfig(level=logging.DEBUG if opts.verbose else
                            logging.INFO)

    if opts.function:
        return opts.function(opts)
    else:
        p.print_help()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号