Files
gaokao-volunteer-system/data/cli_compat_gaokao_shortlink.py
Hermes 77cde03f1d
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled
feat(cli): delegate share/payment-doctor to gaokao-cli (phase 3 batch 2)
Builds on 7d31d75 (order delegation + doctor self-check). The unified
gaokao-cli now also wraps the legacy shortlink and payment-doctor
scripts through thin runpy-based compat shims.

- data/cli_compat_gaokao_shortlink.py: loads scripts/gaokao-shortlink
  via runpy.run_path; preserves argv routing for native subcommands
  (create/list/resolve/revoke/...).
- data/cli_compat_payment_doctor.py: loads scripts/payment_provider_doctor.py;
  strips the leading 'doctor' marker (the legacy script takes no args)
  and rejects unrecognised tokens so silent flag drops are surfaced.
- data/rules/cli.py main(): routes gaokao-cli {share,payment} <...>
  to the compat shims; gaokao-cli order remains delegated to
  data.orders.cli.
- docs/CLI_API_MAPPING.md §2.1: records the actually-shipped command
  surface (rules / majors / majors school-* / audit / order / share /
  payment doctor / doctor) so the design doc matches runtime.
- tests/test_cli_doctor_phase3.py: covers share delegation, payment
  doctor rejection, and the passthrough help flow.

Verification:
- focused: 6 passed
- dev-verify full gate: all checks passed (ruff / mypy / coverage / pytest / benchmark)
2026-06-17 19:16:44 +08:00

42 lines
1.4 KiB
Python

"""Thin import shim for the legacy `gaokao-shortlink` script.
The script is shipped as a top-level module under `scripts/`. It uses
argparse directly and does not expose a stable Python entrypoint, so
we exec it via `runpy` and forward `main(argv)`.
"""
from __future__ import annotations
import argparse
import runpy
import sys
from pathlib import Path
_SCRIPT_PATH = Path(__file__).resolve().parent.parent / "scripts" / "gaokao-shortlink"
def main(argv: list[str] | None = None) -> int:
if not _SCRIPT_PATH.is_file():
raise FileNotFoundError(f"gaokao-shortlink not found at {_SCRIPT_PATH}")
previous_argv = sys.argv
try:
if argv is None:
sys.argv = [str(_SCRIPT_PATH), *previous_argv[1:]]
else:
sys.argv = [str(_SCRIPT_PATH), *argv]
# run_path returns the script's global namespace; we rely on
# `if __name__ == "__main__"` running main() and raising SystemExit.
runpy.run_path(str(_SCRIPT_PATH), run_name="__main__")
except SystemExit as exc:
return int(exc.code) if exc.code is not None else 0
finally:
sys.argv = previous_argv
# If the script didn't call sys.exit (unlikely), surface 0.
return 0
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="gaokao-shortlink compat entrypoint")
parser.parse_args()
raise SystemExit(main(sys.argv[1:]))