示例工程 40-type-checker-in-python
40-type-checker-in-python/05-cli/README.md
# 05 · cli
**演示**:把检查器包成命令行工具:多文件、`path:line:col: error: ... [CODE]` 输出、有错退出 1、正常退出 0、文件不可读退出 2。
**运行**:
```sh
printf 'x = 1\ny = x + "a"\n' > /tmp/demo.py
uv run python examples/40-type-checker-in-python/05-cli/cli.py /tmp/demo.py
echo "exit=$?"
```
**预期输出**(3.12.9):
```text
/tmp/demo.py:2:4: error: unsupported operands: int and str [E001]
Found 1 error
exit=1
```
**依赖**:仅标准库(`argparse`/`ast`/`sys`)。
**注意**:退出码 0/1/2 分别表示「无错 / 有类型错误 / 工具错误」,CI 与编辑器都依赖这个约定。`col_offset` 是 0-based,这里直接打印,和 mypy 的 1-based 列号差一。