sungguk's picture
Release visual answerability benchmark v1.0.0
e1ced61 verified
Raw
History Blame Contribute Delete
1.6 kB
"""Shared helper for command-line entry points that are not yet implemented.
A phase-P0 build wires every declared console entry point so that ``--help``
documents the intended interface, but any actual dispatch fails loudly with a
non-zero exit. This is deliberately *not* a silent success: the runbook forbids
pretending a command works before it is implemented.
"""
from __future__ import annotations
import sys
from typing import Any
def not_implemented(prog: str, subcommands: dict[str, str]) -> int:
"""Print a not-implemented message and return a non-zero exit code.
``subcommands`` maps subcommand name to a one-line description so the
planned interface remains visible in the error output.
"""
print(f"{prog}: no subcommand is implemented in this build.", file=sys.stderr)
print("Planned subcommands:", file=sys.stderr)
for name, description in subcommands.items():
print(f" {name:<22} {description}", file=sys.stderr)
print(
"Implementing these is tracked in docs/07_IMPLEMENTATION_TASKS.md.",
file=sys.stderr,
)
return 2
def dispatch(
prog: str,
argv: list[str] | None,
subcommands: dict[str, str],
implementations: dict[str, Any] | None = None,
) -> int:
"""Dispatch to an implemented subcommand or report not-implemented."""
implementations = implementations or {}
if not argv:
return not_implemented(prog, subcommands)
command = argv[0]
if command in implementations:
return int(implementations[command](argv[1:]))
return not_implemented(prog, subcommands)