#! /usr/bin/env python
"""生成vscode的调试配置。执行后将对应配置复制到launch.json中即可。
"""
import sys
import os
import jstyleson as json
from pprint import pprint
if __name__ == "__main__":
    cwd = os.getcwd()
    file_ = sys.argv[2]
    args = sys.argv[3:]
    if os.path.exists('.vscode/launch.json'):
        launch = json.load(open('.vscode/launch.json'))
    else:
        launch = {
            "version": "0.2.0",
            "configurations": []
        }

    config = {
        "name": f"Python: {' '.join(sys.argv[2:])}",
        "type": "python",
        "request": "launch",
        "program": f"{file_}",
        "console": "integratedTerminal",
        "args": args,
        "cwd": cwd
    }

    launch['configurations'].append(config)
    if not os.path.exists('.vscode'):
        os.makedirs('.vscode')
    with open('.vscode/launch.json', 'w') as f:
        json.dump(launch, f, indent=4)

