# search-flight 命令参考

`search-flight` 用于搜索航班，支持单程和往返查询。

## 使用前提

首次使用前必须配置 API Key：

```bash
feihuo config set api-key xxxxxx
```

## 命令格式

```bash
feihuo search-flight --dep <出发地> --arr <到达地> --dep-date <出发日期> [--back-date <返程日期>] [--berth-type <舱位等级>]
```

## 参数

| 参数 | 必填 | 说明 |
| --- | --- | --- |
| `--dep <dep>` | 是 | 出发地，可以是城市或机场名称，例如：`上海` |
| `--arr <arr>` | 是 | 到达地，可以是城市或机场名称，例如：`东京` |
| `--dep-date <depDate>` | 是 | 出发日期，格式：`YYYY-MM-DD`，不能早于今天 |
| `--back-date <backDate>` | 否 | 返程日期，格式：`YYYY-MM-DD`，不能早于出发日期 |
| `--berth-type <berthType>` | 否 | 舱位等级：`Y` 经济舱，`C` 公务舱，`F` 头等舱 |

## 示例

单程：

```bash
feihuo search-flight --dep "上海" --arr "东京" --dep-date 2026-03-20
```

往返：

```bash
feihuo search-flight --dep "上海" --arr "东京" --dep-date 2026-03-20 --back-date 2026-03-25
```

指定舱位：

```bash
feihuo search-flight --dep "上海" --arr "东京" --dep-date 2026-03-20 --back-date 2026-03-25 --berth-type Y
```

查看帮助：

```bash
feihuo search-flight --help
```

## 输出

命令输出 JSON。顶层结构为：

```json
{
  "journeys": []
}
```

`journeys` 是航班方案列表。每个方案包含：

| 字段 | 说明 |
| --- | --- |
| `basePrice` | 票面基础价格 |
| `tax` | 税费 |
| `totalPrice` | 总价，包含基础价格和税费 |
| `segments` | 航段列表 |
| `jumpUrl` | 跳转/预订地址 |

`segments` 中每个航段包含：

| 字段 | 说明 |
| --- | --- |
| `segmentCode` | 航段编码 |
| `totalFlightTime` | 航段总飞行时长，格式为 `H:mm`，例如 `1:25` 表示 1 小时 25 分钟 |
| `segmentType` | 航段类型，例如直达或转机 |
| `legs` | 组成该航段的航班列表 |

`legs` 中每个航班包含：

| 字段 | 说明 |
| --- | --- |
| `depCityName` | 出发城市名称 |
| `depDateTime` | 出发日期时间 |
| `depAirportName` | 出发机场名称 |
| `depTerm` | 出发航站楼 |
| `arrCityName` | 到达城市名称 |
| `arrDateTime` | 到达日期时间 |
| `arrAirportName` | 到达机场名称 |
| `arrTerm` | 到达航站楼 |
| `airlineName` | 航空公司名称 |
| `flightNumber` | 格式化后的航班号 |
| `berthTypeName` | 舱位类型名称 |
| `flightTime` | 当前航班飞行时长，格式为 `H:mm` |

## 展示建议

向用户展示结果时，优先展示：

- 总价、基础价和税费
- 出发/到达城市、机场、航站楼
- 出发/到达时间
- 航空公司和航班号
- 总飞行时长和航班飞行时长
- 预订链接：`[点击预订]({jumpUrl})`

如果有多个方案，建议使用 Markdown 表格进行比较。
