# Revoke CLI
命令行工具,用于管理 Revoke 微服务基础设施。
## 安装
```bash
cargo install --path .
```
## 使用方法
### 服务管理
```bash
# 列出所有服务
revoke service list
# 注册新服务
revoke service register my-service -a 127.0.0.1 -p 8080 -t api -t v1
# 注销服务
revoke service deregister service-id
# 查看服务详情
revoke service info my-service
# 检查服务健康状态
revoke service check my-service
```
### 配置管理
```bash
# 获取配置值
revoke config get database.url
# 设置配置值
revoke config set database.url "postgres://localhost/mydb"
# 删除配置
revoke config delete database.url
# 列出配置
revoke config list --prefix database
# 监听配置变化
revoke config watch database.url
# 导出配置
revoke config export -o config.yaml -f yaml
# 导入配置
revoke config import config.yaml
```
### 网关管理
```bash
# 列出路由
revoke gateway routes
# 添加路由
revoke gateway add-route /api/users user-service -m GET -m POST
# 删除路由
revoke gateway remove-route route-id
# 查看统计信息
revoke gateway stats
# 测试配置
revoke gateway test -c gateway.yaml
```
### 分布式追踪
```bash
# 列出最近的追踪
revoke trace list -r 1h -l 100
# 获取追踪详情
revoke trace get trace-id
# 搜索追踪
revoke trace search "error" -r 24h
# 导出追踪
revoke trace export traces.json -f json -r 1h
```
### 健康检查
```bash
# 检查系统健康状态
revoke health check --detailed
# 检查特定服务
revoke health service my-service
# 监控健康状态
revoke health monitor -i 5 -s user-service -s order-service
```
### 项目管理
```bash
# 初始化新项目
revoke init my-project --template microservice
# 启动开发环境
revoke dev --all
# 启动特定服务
revoke dev -s user-service -s order-service
```
## 配置
CLI 工具通过以下方式配置:
1. 命令行参数 `--config`
2. 环境变量 `REVOKE_CONFIG`
3. 默认配置文件 `~/.config/revoke/config.toml`
示例配置文件:
```toml
consul_address = "http://localhost:8500"
config_namespace = "revoke"
trace_endpoint = "http://localhost:4317"
default_timeout = 30
```
## 全局选项
- `-c, --config <FILE>`: 指定配置文件
- `-v, --verbose`: 增加输出详细程度(可多次使用)
## 输出格式
许多命令支持不同的输出格式:
- `table`: 表格格式(默认)
- `json`: JSON 格式
- `yaml`: YAML 格式
例如:
```bash
revoke service list --format json
```
## 环境变量
- `REVOKE_CONFIG`: 配置文件路径
- `CONSUL_ADDR`: Consul 地址
- `RUST_LOG`: 日志级别
## 示例
### 完整的服务部署流程
```bash
# 1. 初始化项目
revoke init my-service --template microservice
# 2. 进入项目目录
cd my-service
# 3. 启动开发环境
revoke dev --all
# 4. 检查服务状态
revoke service list
revoke health check
# 5. 配置服务
revoke config set my-service.database.url "postgres://localhost/mydb"
revoke config set my-service.cache.ttl "300"
# 6. 查看服务追踪
revoke trace list -s my-service
```
### 监控和调试
```bash
# 实时监控服务健康状态
revoke health monitor --all
# 查看网关统计
revoke gateway stats
# 搜索错误追踪
revoke trace search "status_code:500" -r 1h
# 导出配置备份
revoke config export -o backup.yaml
```