|
| 1 | +# Flashduty CLI |
| 2 | + |
| 3 | +[English](README.md) | 中文 |
| 4 | + |
| 5 | +[Flashduty](https://flashcat.cloud) 平台的命令行工具。在终端中管理故障、值班、状态页等。 |
| 6 | + |
| 7 | +## 安装 |
| 8 | + |
| 9 | +### macOS / Linux |
| 10 | + |
| 11 | +```bash |
| 12 | +curl -sSL https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.sh | sh |
| 13 | +``` |
| 14 | + |
| 15 | +### Windows (PowerShell) |
| 16 | + |
| 17 | +```powershell |
| 18 | +irm https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.ps1 | iex |
| 19 | +``` |
| 20 | + |
| 21 | +### Go Install |
| 22 | + |
| 23 | +```bash |
| 24 | +go install github.com/flashcatcloud/flashduty-cli/cmd/flashduty@latest |
| 25 | +``` |
| 26 | + |
| 27 | +### 手动下载 |
| 28 | + |
| 29 | +从 [GitHub Releases](https://github.com/flashcatcloud/flashduty-cli/releases) 下载适合您平台的最新版本。 |
| 30 | + |
| 31 | +### 选项 |
| 32 | + |
| 33 | +| 变量 | 说明 | 默认值 | |
| 34 | +|------|------|--------| |
| 35 | +| `FLASHDUTY_VERSION` | 安装指定版本(如 `v0.1.2`) | 最新版 | |
| 36 | +| `FLASHDUTY_INSTALL_DIR` | 自定义安装目录 | `/usr/local/bin`(Shell)、`~\.flashduty\bin`(PowerShell) | |
| 37 | + |
| 38 | +## 快速开始 |
| 39 | + |
| 40 | +### 1. 认证 |
| 41 | + |
| 42 | +```bash |
| 43 | +flashduty login |
| 44 | +``` |
| 45 | + |
| 46 | +系统会提示输入 Flashduty APP Key。获取方式:登录 [Flashduty 控制台](https://console.flashcat.cloud),进入 **账户设置 > APP Key**。 |
| 47 | + |
| 48 | +也可以通过环境变量设置: |
| 49 | + |
| 50 | +```bash |
| 51 | +export FLASHDUTY_APP_KEY=your_app_key |
| 52 | +``` |
| 53 | + |
| 54 | +### 2. 使用 |
| 55 | + |
| 56 | +```bash |
| 57 | +# 列出最近的故障 |
| 58 | +flashduty incident list |
| 59 | + |
| 60 | +# 查看故障详情 |
| 61 | +flashduty incident get <incident_id> |
| 62 | + |
| 63 | +# 列出团队成员 |
| 64 | +flashduty member list |
| 65 | + |
| 66 | +# 查看协作空间 |
| 67 | +flashduty channel list |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 认证方式 |
| 73 | + |
| 74 | +CLI 按以下优先级解析凭证(优先级从高到低): |
| 75 | + |
| 76 | +1. `--app-key` 参数(隐藏参数,用于脚本) |
| 77 | +2. `FLASHDUTY_APP_KEY` 环境变量 |
| 78 | +3. `~/.flashduty/config.yaml`(由 `flashduty login` 写入) |
| 79 | + |
| 80 | +### 配置文件 |
| 81 | + |
| 82 | +存储在 `~/.flashduty/config.yaml`,权限为 `0600`: |
| 83 | + |
| 84 | +```yaml |
| 85 | +app_key: your_app_key |
| 86 | +base_url: https://api.flashcat.cloud |
| 87 | +``` |
| 88 | +
|
| 89 | +### 配置命令 |
| 90 | +
|
| 91 | +```bash |
| 92 | +flashduty config show # 查看当前配置(密钥已脱敏) |
| 93 | +flashduty config set app_key KEY # 设置 APP Key |
| 94 | +flashduty config set base_url URL # 覆盖 API 地址 |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## 全局参数 |
| 100 | + |
| 101 | +| 参数 | 说明 | |
| 102 | +|------|------| |
| 103 | +| `--json` | 以 JSON 格式输出 | |
| 104 | +| `--no-trunc` | 表格输出时不截断长字段 | |
| 105 | +| `--base-url` | 覆盖 API 地址 | |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## 可用命令 |
| 110 | + |
| 111 | +### `incident` - 故障生命周期管理(9 个命令) |
| 112 | + |
| 113 | +```bash |
| 114 | +flashduty incident list [flags] # 列出故障(默认最近 24 小时) |
| 115 | +flashduty incident get <id> [<id2>] # 查看故障详情(单个 ID 时显示详细视图) |
| 116 | +flashduty incident create [flags] # 创建故障(缺少参数时进入交互模式) |
| 117 | +flashduty incident update <id> [flags] # 更新故障字段 |
| 118 | +flashduty incident ack <id> [<id2>] # 认领故障 |
| 119 | +flashduty incident close <id> [<id2>] # 关闭故障 |
| 120 | +flashduty incident timeline <id> # 查看故障时间线 |
| 121 | +flashduty incident alerts <id> # 查看故障告警 |
| 122 | +flashduty incident similar <id> # 查找相似故障 |
| 123 | +``` |
| 124 | + |
| 125 | +**列表参数:** |
| 126 | + |
| 127 | +| 参数 | 说明 | 默认值 | |
| 128 | +|------|------|--------| |
| 129 | +| `--progress` | 筛选:Triggered、Processing、Closed | 全部 | |
| 130 | +| `--severity` | 筛选:Critical、Warning、Info | 全部 | |
| 131 | +| `--channel` | 按协作空间 ID 筛选 | - | |
| 132 | +| `--title` | 按标题关键字搜索 | - | |
| 133 | +| `--since` | 开始时间(时长、日期、日期时间或 Unix 时间戳) | `24h` | |
| 134 | +| `--until` | 结束时间 | `now` | |
| 135 | +| `--limit` | 最大结果数 | `20` | |
| 136 | +| `--page` | 页码 | `1` | |
| 137 | + |
| 138 | +**时间格式示例:** `5m`、`1h`、`24h`、`168h`、`2026-04-01`、`2026-04-01 10:00:00`、`1712000000` |
| 139 | + |
| 140 | +### `change` - 变更记录查询(1 个命令) |
| 141 | + |
| 142 | +```bash |
| 143 | +flashduty change list [flags] # 列出变更记录(部署、配置等) |
| 144 | +``` |
| 145 | + |
| 146 | +支持 `--channel`、`--since`、`--until`、`--type`、`--limit`、`--page`。 |
| 147 | + |
| 148 | +### `member` - 成员查询(1 个命令) |
| 149 | + |
| 150 | +```bash |
| 151 | +flashduty member list [flags] # 列出成员 |
| 152 | +``` |
| 153 | + |
| 154 | +支持 `--name`、`--email`、`--page`。 |
| 155 | + |
| 156 | +### `team` - 团队查询(1 个命令) |
| 157 | + |
| 158 | +```bash |
| 159 | +flashduty team list [flags] # 列出团队及成员 |
| 160 | +``` |
| 161 | + |
| 162 | +支持 `--name`、`--page`。 |
| 163 | + |
| 164 | +### `channel` - 协作空间查询(1 个命令) |
| 165 | + |
| 166 | +```bash |
| 167 | +flashduty channel list [flags] # 列出协作空间 |
| 168 | +``` |
| 169 | + |
| 170 | +支持 `--name`。 |
| 171 | + |
| 172 | +### `escalation-rule` - 分派策略查询(1 个命令) |
| 173 | + |
| 174 | +```bash |
| 175 | +flashduty escalation-rule list --channel <id> # 按协作空间 ID 查询 |
| 176 | +flashduty escalation-rule list --channel-name <name> # 按协作空间名称查询(自动解析) |
| 177 | +``` |
| 178 | + |
| 179 | +### `field` - 自定义字段查询(1 个命令) |
| 180 | + |
| 181 | +```bash |
| 182 | +flashduty field list [flags] # 列出自定义字段定义 |
| 183 | +``` |
| 184 | + |
| 185 | +支持 `--name`。 |
| 186 | + |
| 187 | +### `statuspage` - 状态页管理(4 个命令) |
| 188 | + |
| 189 | +```bash |
| 190 | +flashduty statuspage list [--id <ids>] # 列出状态页 |
| 191 | +flashduty statuspage changes --page-id <id> --type <incident|maintenance> # 列出活跃的变更 |
| 192 | +flashduty statuspage create-incident --page-id <id> --title <title> # 创建状态页事件 |
| 193 | +flashduty statuspage create-timeline --page-id <id> --change <id> --message <msg> # 添加时间线更新 |
| 194 | +``` |
| 195 | + |
| 196 | +### `template` - 通知模板管理(4 个命令) |
| 197 | + |
| 198 | +```bash |
| 199 | +flashduty template get-preset --channel <channel> # 获取预设模板代码 |
| 200 | +flashduty template validate --channel <channel> --file <path> # 验证并预览模板 |
| 201 | +flashduty template variables [--category <category>] # 列出模板变量 |
| 202 | +flashduty template functions [--type custom|sprig|all] # 列出模板函数 |
| 203 | +``` |
| 204 | + |
| 205 | +支持的通知渠道:`dingtalk`、`dingtalk_app`、`feishu`、`feishu_app`、`wecom`、`wecom_app`、`slack`、`slack_app`、`telegram`、`teams_app`、`email`、`sms`、`zoom`。 |
| 206 | + |
| 207 | +### 工具命令 |
| 208 | + |
| 209 | +```bash |
| 210 | +flashduty login # 交互式认证 |
| 211 | +flashduty config show # 查看当前配置 |
| 212 | +flashduty config set # 设置配置项 |
| 213 | +flashduty version # 打印版本信息 |
| 214 | +flashduty completion # 生成 Shell 自动补全(bash/zsh/fish/powershell) |
| 215 | +``` |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +## 输出格式 |
| 220 | + |
| 221 | +**表格(默认):** 人类可读,列对齐,长字段自动截断。 |
| 222 | + |
| 223 | +``` |
| 224 | +ID TITLE SEVERITY PROGRESS CHANNEL CREATED |
| 225 | +inc_abc123 DB connection timeout Critical Triggered Production 2026-04-10 10:23 |
| 226 | +inc_def456 High memory usage Warning Processing Staging 2026-04-10 09:15 |
| 227 | +Showing 2 results (page 1, total 2). |
| 228 | +``` |
| 229 | + |
| 230 | +**JSON(`--json`):** 机器可解析,完整数据,不截断。 |
| 231 | + |
| 232 | +```bash |
| 233 | +flashduty incident list --json | jq '.[].title' |
| 234 | +``` |
| 235 | + |
| 236 | +**不截断(`--no-trunc`):** 表格显示完整字段内容。 |
| 237 | + |
| 238 | +--- |
| 239 | + |
| 240 | +## 开发 |
| 241 | + |
| 242 | +### 前置条件 |
| 243 | + |
| 244 | +- Go 1.24+ |
| 245 | +- golangci-lint(Makefile 自动安装) |
| 246 | + |
| 247 | +### 构建 |
| 248 | + |
| 249 | +```bash |
| 250 | +make build # 构建二进制文件到 bin/flashduty |
| 251 | +make test # 运行测试(启用竞态检测) |
| 252 | +make lint # 运行代码检查 |
| 253 | +make check # 运行所有检查(格式化、检查、测试、构建) |
| 254 | +make help # 显示所有可用目标 |
| 255 | +``` |
| 256 | + |
| 257 | +### 依赖 |
| 258 | + |
| 259 | +| 包 | 用途 | |
| 260 | +|----|------| |
| 261 | +| [flashduty-sdk](https://github.com/flashcatcloud/flashduty-sdk) | Flashduty API 客户端 | |
| 262 | +| [cobra](https://github.com/spf13/cobra) | CLI 框架 | |
| 263 | +| [yaml.v3](https://pkg.go.dev/gopkg.in/yaml.v3) | 配置文件解析 | |
| 264 | +| [x/term](https://pkg.go.dev/golang.org/x/term) | 密码输入脱敏 | |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +## 许可证 |
| 269 | + |
| 270 | +本项目基于 MIT 许可证开源 - 详见 [LICENSE](LICENSE) 文件。 |
0 commit comments