# CloudCC 配置模块开发指南

## 1. 模块定位

`config` 模块用于管理本地项目配置文件 `cloudcc-cli.config.js` 的环境切换与查看。

当前支持：

- 切换当前环境：`cloudcc use config <env> [projectPath]`
- 查看当前配置：`cloudcc get config [projectPath]`
- 查看开发文档：`cloudcc doc config devguide`

---

## 2. 开发前准备

执行命令前请确认：

- 已完成 `cloudcc doc project devguide` 的初始化流程
- 项目根目录存在 `cloudcc-cli.config.js`
- `cloudcc-cli.config.js` 中包含可切换的环境配置（如 `test`、`prod`）

---

## 3. 命令总览（以当前实现为准）

```bash
cloudcc use config <env> [projectPath]
cloudcc get config [projectPath]
cloudcc doc config devguide
```

参数约定：

- `env`：目标环境名称（例如 `test`、`prod`）
- `projectPath`：项目路径，不传时默认当前目录

---

## 4. 切换环境

```bash
cloudcc use config <env> [projectPath]
```

说明：

- 命令会读取 `<projectPath>/cloudcc-cli.config.js`
- 将 `use` 字段更新为传入的 `env`
- 写回配置文件后，后续命令将按新的 `use` 环境读取连接信息

示例：

```bash
# Switch the current directory to the test environment
cloudcc use config test .
```

---

## 5. 查看配置

```bash
cloudcc get config [projectPath]
```

说明：

- 命令会读取并输出当前配置对象
- 不传 `projectPath` 时默认读取当前目录

示例：

```bash
# View the current directory configuration
cloudcc get config .
```

---

## 6. 常见注意事项

- 执行路径错误会导致找不到 `cloudcc-cli.config.js`
- `env` 必须是配置中可识别的环境名称，否则后续命令可能读取失败
- 切换环境后建议立即执行一次 `cloudcc get config .` 进行确认

---

## 7. 推荐操作顺序

```bash
# 1) View the current configuration
cloudcc get config .

# 2) Switch to the target environment
cloudcc use config test .

# 3) View again to confirm it has taken effect
cloudcc get config .
```
