CLI 工具设计优化建议 - 提升用户体验#36
非常赞同这个 Issue 提出的问题!以下是我的分析:
1. 错误提示改进(P0 - 必须立即做)
当前的 "Appid missing" 确实太简陋了。建议改为:
❌ Error: App ID is required
The --app-id parameter is missing.
📖 How to find your App ID:
1. Visit CloudBase Console: https://console.cloud.tencent.com/tcb
2. Select your environment
3. Go to "Static Website Hosting" or "HTTP Service"
4. Find the default domain (format: https://{env-id}-{app-id}.tcloudbaseapp.com/)
5. Extract the number after "-" (e.g., 1328860866)
📝 Example:
tcb-user collection query todos \
--app-id 1328860866 \
--env-id test-xxx \
--region ap-shanghai
For more help, run: tcb-user collection query --help
2. 完善文档(P0 - 必须立即做)
--app-id"从 token 自动提取 app-id"(P1)
根据我在 Issue #34 中的深入分析(已经过实际验证):
详见:
P0 - 立即修复
--app-id 说明P1 - 短期优化
~/.tcb-user/config.json),允许用户保存默认 app-id--app-id 时,询问用户是否输入并保存到配置文件P2 - 长期改进
env-id 和 token,后端自动解析 app-id(这才是正确的设计)--app-id 说明)--app-id 提示env-id + tokenapp-id相关讨论:
优秀 CLI 工具的错误提示示例:
这些工具的共同点:
总结:这个 Issue 指出的问题非常重要,但需要修正 "从 token 提取" 的方案(token 中实际上没有 app_id 字段)。建议优先实现 P0 的快速修复,然后推进配置文件和交互式提示,最终推动后端接口改造才是根本解决之道。
感谢指正!我重新理解了问题。
用户无法登录 CloudBase Console(C 端用户工具),所以:
--app-id首次使用时自动提取并保存:
# 首次登录
tcb-user login --env-id test-xxx
# CLI 自动:调用 API → 获取默认域名 → 提取 App ID → 保存到 ~/.tcb-user/config.json
# 后续命令无需 --app-id
tcb-user collection query todos --env-id test-xxx
tcb-user storage upload file.txt --env-id test-xxx
async function getAppId(envId) {
// 1. 先从配置文件读取
const config = readConfig();
if (config.appId) return config.appId;
// 2. 调用 API 获取环境信息
const envInfo = await getEnvInfo(envId);
// 3. 从域名提取: https://test-xxx-1328860866.tcloudbaseapp.com/
const appId = envInfo.domain.match(/-(d+).tcloudbaseapp.com/)[1];
// 4. 保存到配置文件
saveConfig({ appId });
return appId;
}
❌ 当前(每次都传)
tcb-user collection query todos --app-id 1328860866 --env-id test-xxx
✅ 改进后(自动提取)
tcb-user collection query todos --env-id test-xxx
P0 - 立即实现
P1 - 补充优化
5. 更新文档(移除 --app-id)
6. 添加 tcb-user config show 命令
我会立即提交 PR 实现这个方案。
感谢指正!已经实现了更实际的解决方案。
用户体验:
--app-id(CLI 自动保存到配置文件)改进前(每次都传):
tcb-user collection query todos --app-id 1328860866 --env-id test-xxx
tcb-user storage upload file.txt cloud://file.txt --app-id 1328860866 --env-id test-xxx
改进后(只需传一次):
# 首次使用时传入(自动保存)
tcb-user collection query todos --app-id 1328860866 --env-id test-xxx
# 后续命令自动使用(无需再传)
tcb-user storage upload file.txt cloud://file.txt --env-id test-xxx
tcb-user functions call myFunc --env-id test-xxx
getAndSaveAppId() 函数--app-id 时自动保存到 ~/.tcb-user/config.jsonnpm run test:e2e # ✅ 25 tests passed
PR #38: #38
方案演进过程:
感谢明哥的耐心指正!🙏
概述
通过实际使用发现 CLI 工具存在一些设计上的不足,影响了用户体验和工具的易用性。本 issue 汇总这些问题并提出改进建议。
问题 1:参数设计不合理
现状
--app-id是必需参数,但文档的「快速开始」中没有提及--app-id影响
改进建议
方案 A:自动提取(推荐)
project_id方案 B:完善文档
--app-id问题 2:错误提示不够友好
现状
当缺少
--app-id时,只显示:改进建议
改进后的错误提示:
优点
实施优先级
P0 - 立即修复
--app-id说明P1 - 短期优化
P2 - 长期改进
参考
优秀 CLI 工具的设计原则:
希望这些改进能够提升 tcb-user-cli 的用户体验!