Files
lightcore-cli/README.md
T

102 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LightCore CLI
LightCore CLI 提供 System、Media、Fangyus、恒德、GYSmart 和 Shop 的后台命令。
## 安装
使用 Python 3.10 或更新版本。从远程仓库安装需要 Git。
```powershell
python -m pip install "lightcore-cli @ git+https://code.zhecent.com/open/lightcore-cli.git"
lightcore --help
```
从已克隆的源码安装时,在仓库根目录运行 `python -m pip install .`。
更新到同一版本号的较新提交时,可在安装命令中加 `--force-reinstall`。
## 登录与会话
独立安装时,CLI 将各应用的会话存到用户目录下的 `.lightcore/lightcore-api/<应用>/.env`。例如 System 使用 `system/.env`,Media 使用 `media/.env`。从 LightCore 或相邻的 plan 工作区执行时,CLI 使用 LightCore 下的 `.work/lightcore-api/<应用>/.env`。可在应用名后传 `--env-file` 指定会话文件,登录和后续命令使用同一路径。
System 首次登录时指定目标后端。将示例域名换成实际地址,在终端中按提示输入管理员账号和密码。
```powershell
lightcore system login --base-url https://system.example.com
lightcore media login
lightcore system --help
lightcore media --help
lightcore api --help
```
Media 拒绝账号或密码时会重新提示输入,按 `Ctrl+C` 可取消。
## System
使用独立会话文件连接本地开发实例。
```powershell
lightcore system --env-file .work/system-local.env login --base-url http://localhost:8888
lightcore system --env-file .work/system-local.env monitor server
lightcore system trace detail --help
lightcore system storage-clients create --example
```
完整操作从 `lightcore system --help` 查找。凭据、对象访问 URL 和证书下载使用 `--output` 保存到私有文件。
## Media
```text
lightcore media files find --keyword "推窗器"
lightcore media files list --document-id 58
lightcore media files upload "推窗器说明书.pdf"
lightcore media files get --document-id 58 --file-id 123 --file-id 124
```
`find` 返回文档 ID 和标题。上传返回 `fileId`,可以在 Media 里关联到产品文档。下载按文档验证附件,默认写到执行目录的 `.work/media/58/`。每项结果包含文件 ID 与保存路径,遇到同名目标时报告失败。命令参数和示例通过相应的 `--help` 查看。
上传响应超时后,核对原操作再使用错误输出中的 `requestId` 发起重试。临时下载、应用会话和本机配置留在使用设备。不同用户用自己的 Media 账号登录。
Media 的子命令覆盖后台登录、刷新和退出、个人资料、管理员、社媒账号、稿件、参考内容、发布登记、文档、短剧、文件和存储绑定。
从 `lightcore media --help` 找命令组,在具体命令末尾加 `--help` 查参数。例如 `contents list --help` 显示 `--page-size` 范围 1–100、默认 20,以及 `--content-type` 的可选值。
```text
lightcore media contents list --help
lightcore media videos save --schema
lightcore media videos save --example
lightcore media videos save --example update
```
接受 JSON 的命令提供 `--schema` 和 `--example`,无需会话即可查看。字段说明包含类型、枚举、嵌套结构和必填条件。示例中的 ID、正文和时间是占位内容,更新前读取实际记录的 ID 和 `updatedAt`。填写后用 `--body-file` 提交 UTF-8 JSON。涉及密码或存储密钥时,使用本机私有文件。跨字段约束、权限和服务端校验以对应应用契约为准。
```text
lightcore media accounts list --page-size 20
lightcore media projects context --project-id 58
lightcore media contents save --body-file .work/content.json
lightcore media videos download --video-id 58 --file-id 123 --output .work/参考图.png
```
## Fangyus、恒德、GYSmart 和 Shop
使用各应用后台账号登录。要同时操作不同部署,为每个目标指定独立的 `--env-file`。离线查看命令用法、请求形状和示例无需登录。
```text
lightcore fangyus --env-file .work/fangyus-local.env login --base-url http://localhost:8888
lightcore fangyus --env-file .work/fangyus-local.env article create --body-file .work/article.json --dry-run
lightcore hengde --help
lightcore gysmart email save-config --schema
lightcore shop crm catalog product apply --schema
lightcore shop file upload --file .work/product.png --body-file .work/upload.json
```
Shop 提供展厅、公共文件、抖音生活服务、内容及渠道、CRM 和商城。Plan 与 Apply 的请求形状分别通过各自的 `--schema` 查看。请求超时后先用原 `requestId` 查回执,或凭请求号核对操作结果。商城视觉包还需要当前源码构建的根 `light` 和宿主机 Chromium,可用 `--renderer` 指定 `light` 路径。
也可使用 `lightcore api` 按应用契约调用后台相对路径。
从当前工作目录接收 `responseFile` 摘要时,读取 CLI 返回的完整响应文件以获取截断部分。
## 测试
在本目录运行 `python -m unittest discover -s tests`,使用本机 HTTP 服务验证命令。与 Go 后台路由的比对需要完整 LightCore 源码。