fix(rawcli): friendly message when prompt_toolkit isn't installed

`pm3py rawcli` lives behind the optional [rawcli] extra; a plain install
of pm3py doesn't pull prompt_toolkit. Catch the ModuleNotFoundError and
print an install hint (pip install 'pm3py[rawcli]') with exit code 2,
instead of dumping a traceback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
michael
2026-07-14 12:21:20 -07:00
parent f76663f798
commit ae3fd3d4ea

View File

@@ -6,6 +6,7 @@ is left for ``flash`` (wrapping pm3flash) and a future ``client`` command CLI.
from __future__ import annotations
import argparse
import sys
def build_parser() -> argparse.ArgumentParser:
@@ -20,6 +21,16 @@ def main(argv: list[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
if args.command == "rawcli":
try:
import prompt_toolkit # noqa: F401
except ModuleNotFoundError:
print(
"pm3py rawcli needs prompt_toolkit, which isn't installed.\n"
" install it with: pip install 'pm3py[rawcli]'\n"
" or directly: pip install prompt_toolkit",
file=sys.stderr,
)
return 2
from pm3py.cli.rawcli.app import run
return run(port=args.port)
parser.print_help()