INNER CODE UNIT · Python
restore
kangarooking/cangjie-skill · scripts/apply_skill_patch.py:57
def restore(target: Path, snapshot: Path) -> int:
if not snapshot.is_dir():
raise SystemExit(f"快照不存在: {snapshot}")
with WriterLock(target):
if target.exists():
shutil.rmtree(target)
shutil.copytree(snapshot, target)
print(f"已恢复 {target} ← {snapshot}")
return 0
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
sub = ap.add_subparsers(dest="mode", required=True)
a = sub.add_parser("apply")
a.add_argument("--target", required=True)
a.add_argument("--patch-dir", required=True)
a.add_argument("--snapshots", required=True)