# License: Apache-2.0 License # Created by: Patrick Lumbantobing, VertoX-AI # Copyright (c) 2026 VertoX-AI. All rights reserved. # # This work is licensed under the Apache-2.0 License. # To view a copy of this license, visit # https://www.apache.org/licenses/LICENSE-2.0 """Compose the thin command-line interface and translate typed errors to exit codes.""" from __future__ import annotations import argparse import sys from collections.abc import Sequence from speech_text_data_aligners.cli import annotate as annotate_cli from speech_text_data_aligners.cli import benchmark as benchmark_cli from speech_text_data_aligners.cli import readiness as readiness_cli from speech_text_data_aligners.core.errors import SpeechTextAlignerError def build_parser() -> argparse.ArgumentParser: """Build the complete CLI parser without constructing a concrete backend. Returns: Configured top-level parser with annotation, benchmark, and offline readiness subcommands. """ parser = argparse.ArgumentParser(prog="speech-text-aligners") subparsers = parser.add_subparsers(dest="command", required=True) annotate_cli.configure_parser(subparsers.add_parser("annotate")) benchmark_cli.configure_parser(subparsers.add_parser("benchmark")) readiness_cli.configure_parser(subparsers.add_parser("readiness")) return parser def main(argv: Sequence[str] | None = None) -> int: """Parse CLI arguments, invoke the selected adapter, and return an exit status. Parameters ---------- argv: Optional explicit argument sequence; defaults to process arguments. Returns ------- Zero on success or two after a safely reportable project error. Side Effects: Delegated commands may create artifacts; typed errors are written to stderr. """ args = build_parser().parse_args(argv) try: return int(args.handler(args)) except SpeechTextAlignerError as error: print(f"error: {error}", file=sys.stderr) return 2 if __name__ == "__main__": raise SystemExit(main())