"""`okstra worktree-lookup` 의 진입점.

핸들러는 [worktree_cli.lookup] 에 있다. 이 모듈은 자기 이름의 파서만 갖는다 —
`python3 -m` 대상 하나가 `okstra` 명령 하나에 대응해야 `--help` 의 prog 와
사용법이 사용자가 실제로 치는 명령과 같아진다.
"""
from __future__ import annotations

import argparse

from .worktree_cli import lookup

_CLI_EPILOG = r"""Usage:
  okstra worktree-lookup <project-id> <task-group> <task-id>

The three identifiers are slugified by the runtime before lookup, so
case/whitespace variants are tolerated.

Output: JSON with the registry entry (worktreePath, branch, baseRef,
status, lastPhase, createdAt). Emits {"ok": true, "entry": null} when
the task-key has no active worktree.
"""


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(
        prog="okstra worktree-lookup",
        description="Look up the registered worktree for a task-key.",
        epilog=_CLI_EPILOG,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument("project_id", metavar="project-id")
    parser.add_argument("task_group", metavar="task-group")
    parser.add_argument("task_id", metavar="task-id")
    return lookup(parser.parse_args(argv))


if __name__ == "__main__":
    raise SystemExit(main())
