# 06 · argparse-subcommands **演示**:`add_subparsers(required=True)` 建子命令;`type=int` 自动转换并校验;缺参数时 argparse 打印用法并以退出码 2 结束。 **运行**: ```sh uv run python examples/16-stdlib-tour/06-argparse-subcommands/argparse_subcommands.py ``` **预期输出**(3.12.9): ```text add: add apple 3 remove: remove apple missing: code=2 mentions_name=True ``` **依赖**:仅标准库。 **注意**:`parse_args` 在库代码里会直接 `SystemExit`,不好测试;业务代码可调 `parse_known_args` 或捕获 `SystemExit`,CLI 入口再让退出码冒泡。