> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bubench.lexmount.io/llms.txt
> Use this file to discover all available pages before exploring further.

# cli_utils

> 命令行参数解析工具

# browseruse\_bench.utils.cli\_utils

命令行参数解析与错误处理工具。

## 导入

```python theme={null}
from browseruse_bench.utils import (
    handle_cli_errors,
    create_run_parser,
    create_eval_parser,
    create_base_agent_parser,
)
```

***

## handle\_cli\_errors

CLI 错误处理装饰器，统一处理异常和退出码。

```python theme={null}
def handle_cli_errors(func: Callable[..., int]) -> Callable[..., None]
```

### 使用示例

```python theme={null}
from browseruse_bench.utils import handle_cli_errors

@handle_cli_errors
def main() -> int:
    # 你的逻辑
    return 0  # 成功

if __name__ == "__main__":
    main()
```

### 行为

| 条件 | 退出码 |
| - | - |
| 正常返回 | 函数返回值 |
| KeyboardInterrupt | 130 |
| 其他异常 | 1 |

***

## create\_run\_parser

为主运行脚本创建参数解析器。

```python theme={null}
def create_run_parser() -> argparse.ArgumentParser
```

### 包含的参数

| 参数 | 类型 | 默认值 | 说明 |
| - | - | - | - |
| `--mode` | choice | `all` | 运行模式：`single`、`first_n`、`specific`、`sample_n`、`by_id`、`all` |
| `--count` | int | 1 | `first_n` 或 `sample_n` 模式下的任务数量 |
| `--task-ids` | list | - | `specific` 模式下的任务 ID 列表 |
| `--id` | str | - | `by_id` 模式下的单个任务 ID |
| `--timeout` | int | - | 每个任务的超时时间（秒） |
| `--skip-completed` | flag | False | 跳过已完成的任务 |
| `--dry-run` | flag | False | 只显示命令，不实际执行 |

***

## create\_eval\_parser

为评估脚本创建参数解析器。

```python theme={null}
def create_eval_parser() -> argparse.ArgumentParser
```

### 包含的参数

| 参数 | 类型 | 默认值 | 说明 |
| - | - | - | - |
| `--mode` | str | - | 评估模式 |
| `--model` | str | - | 评估模型 |
| `--score-threshold` | int | - | 分数阈值（LexBench-Browser=60，其他=3） |
| `--num-worker` | int | 1 | 并行进程数 |
| `--api-key` | str | - | API Key |
| `--base-url` | str | - | API Base URL |
| `--dry-run` | flag | False | 只显示命令，不实际执行 |

***

## create\_base\_agent\_parser

为 Agent `run.py` 创建基础参数解析器。

```python theme={null}
def create_base_agent_parser(
    description: str,
    default_tasks_json: str,
    default_output_dir: str
) -> argparse.ArgumentParser
```

**description** `str` *required*

解析器描述

**default\_tasks\_json** `str` *required*

默认的 tasks JSON 文件路径

**default\_output\_dir** `str` *required*

默认输出目录

### 使用示例

```python theme={null}
from browseruse_bench.utils import create_base_agent_parser

parser = create_base_agent_parser(
    description="Browser-Use Agent Runner",
    default_tasks_json="data/tasks.json",
    default_output_dir="output/"
)
args = parser.parse_args()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.