File size: 2,075 Bytes
51e84d2 fc1dcbc c9761c3 fc1dcbc c9761c3 fc1dcbc c9761c3 fc1dcbc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # 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())
|