import json
import sys

class JSONEngine:
    def __init__(self, config_path):
        self.config_path = config_path

    def load(self):
        with open(self.config_path, 'r') as file:
            return json.load(file)

    def save(self, data):
        with open(self.config_path, 'w') as file:
            json.dump(data, file, indent=2)

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("用法: python json_engine.py {load|save} <文件路径> [<目标文件路径>]")
        sys.exit(1)

    command = sys.argv[1]
    engine = JSONEngine(sys.argv[2])

    if command == "load":
        config_data = engine.load()
        print(json.dumps(config_data, indent=2))
    elif command == "save":
        if len(sys.argv) != 4:
            print("用法: python json_engine.py save <文件路径> <目标文件路径>")
            sys.exit(1)
        with open(sys.argv[3], 'r') as file:
            data = json.load(file)
        engine.save(data)
    else:
        print("无效的命令")
        sys.exit(1)
