cbi-shared

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CreatiBI CLI 基础配置与认证

CreatiBI CLI Basic Configuration and Authentication

CreatiBI 命令行工具的初始化与认证模块。
Initialization and authentication module of the CreatiBI command-line tool.

安装

Installation

bash
undefined
bash
undefined

npm 安装(推荐)

npm installation (recommended)

npm install -g @creatibi/cbi-cli@latest
npm install -g @creatibi/cbi-cli@latest

或使用 npx(无需安装)

Or use npx (no installation required)

npx @creatibi/cbi-cli --help

支持平台:macOS (amd64/arm64)、Linux (amd64/arm64)、Windows (amd64/arm64)

---
npx @creatibi/cbi-cli --help

Supported platforms: macOS (amd64/arm64), Linux (amd64/arm64), Windows (amd64/arm64)

---

快速开始

Quick Start

bash
undefined
bash
undefined

1. 初始化配置(首次使用)

1. Initialize configuration (for first use)

cbi config init
cbi config init

2. OAuth 登录

2. OAuth login

cbi auth login
cbi auth login

3. 确认登录成功

3. Confirm login success

cbi auth whoami

---
cbi auth whoami

---

常用命令速查

Quick Reference for Common Commands

场景命令
初始化配置
cbi config init
强制重新初始化
cbi config init --new
查看配置
cbi config show
登录授权
cbi auth login
查看身份
cbi auth whoami
退出登录
cbi auth logout

ScenarioCommand
Initialize configuration
cbi config init
Force re-initialization
cbi config init --new
View configuration
cbi config show
Login authorization
cbi auth login
Check current identity
cbi auth whoami
Logout
cbi auth logout

配置模块 (config)

Configuration Module (config)

初始化配置

Initialize Configuration

首次使用需要初始化应用凭证配置:
bash
undefined
Initialization of application credential configuration is required for first use:
bash
undefined

初始化配置(交互式输入)

Initialize configuration (interactive input)

cbi config init
cbi config init

强制重新初始化(覆盖已有配置)

Force re-initialization (overwrite existing configuration)

cbi config init --new

**流程:**
1. 检查配置是否已存在
2. 若已存在,需使用 `--new` 强制覆盖
3. 引导输入应用凭证信息:
   - `client_id`(应用 ID)- 必填
   - `client_secret`(应用密钥)- 必填
   - `base_url`(默认 https://open.creatibi.cn)
   - `default_workspace`(可选)
4. 配置写入 `~/.cbi/config.json`

**前提条件:** 在 CreatiBI 开放平台创建应用,获取 client_id 和 client_secret
cbi config init --new

**Process:**
1. Check if configuration already exists
2. If it exists, use `--new` to force overwrite
3. Guide users to enter application credential information:
   - `client_id` (Application ID) - Required
   - `client_secret` (Application Secret) - Required
   - `base_url` (default https://open.creatibi.cn)
   - `default_workspace` (optional)
4. Configuration is written to `~/.cbi/config.json`

**Prerequisite:** Create an application on the CreatiBI Open Platform to obtain client_id and client_secret

显示当前配置

Show Current Configuration

bash
cbi config show              # 显示配置(敏感字段脱敏)
cbi config show -v           # 详细模式(显示登录凭证)
cbi config show --format json   # JSON 格式输出

bash
cbi config show              # Show configuration (sensitive fields desensitized)
cbi config show -v           # Verbose mode (show login credentials)
cbi config show --format json   # Output in JSON format

认证模块 (auth)

Authentication Module (auth)

OAuth 登录

OAuth Login

bash
cbi auth login
前提条件: 已执行
cbi config init
配置应用凭证
流程:
  1. CLI 启动本地回调服务器(端口 8080)
  2. 自动打开浏览器访问授权页面
  3. 用户在浏览器中完成授权
  4. 服务端回调到 CLI 并返回授权码
  5. CLI 用授权码换取 access_token
  6. Token 存储在 ~/.cbi/config.json
bash
cbi auth login
Prerequisite: Executed
cbi config init
to configure application credentials
Process:
  1. CLI starts a local callback server (port 8080)
  2. Automatically opens the browser to access the authorization page
  3. Users complete authorization in the browser
  4. The server callbacks to the CLI and returns an authorization code
  5. CLI exchanges the authorization code for access_token
  6. Token is stored in ~/.cbi/config.json

查看当前身份

Check Current Identity

bash
cbi auth whoami      # 查看当前登录身份
cbi auth whoami -v   # 详细模式(显示 token 信息)
bash
cbi auth whoami      # Check current logged-in identity
cbi auth whoami -v   # Verbose mode (show token information)

退出登录

Logout

bash
cbi auth logout

bash
cbi auth logout

错误处理

Error Handling

权限不足/未登录

Insufficient Permissions/Not Logged In

当遇到
permission denied
auth required
错误时:
bash
undefined
When encountering
permission denied
or
auth required
errors:
bash
undefined

1. 检查配置是否存在

1. Check if configuration exists

cbi config show
cbi config show

2. 如果配置不存在,先初始化

2. If configuration does not exist, initialize first

cbi config init
cbi config init

3. 登录授权

3. Login authorization

cbi auth login
cbi auth login

4. 确认登录成功

4. Confirm login success

cbi auth whoami
undefined
cbi auth whoami
undefined

Token 过期

Token Expired

当遇到
expired access token
错误时:
bash
cbi auth login   # 重新登录
When encountering
expired access token
errors:
bash
cbi auth login   # Log in again

配置文件问题

Configuration File Issues

bash
cbi config init --new   # 强制重新初始化配置
cbi auth login          # 重新登录

bash
cbi config init --new   # Force re-initialization of configuration
cbi auth login          # Log in again

配置文件位置

Configuration File Location

配置存储在
~/.cbi/config.json
json
{
  "base_url": "https://open.creatibi.cn",
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "api_key": "YOUR_ACCESS_TOKEN",
  "refresh_token": "YOUR_REFRESH_TOKEN",
  "token_expires_at": "2026-04-24T00:28:54Z"
}

Configuration is stored in
~/.cbi/config.json
:
json
{
  "base_url": "https://open.creatibi.cn",
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "api_key": "YOUR_ACCESS_TOKEN",
  "refresh_token": "YOUR_REFRESH_TOKEN",
  "token_expires_at": "2026-04-24T00:28:54Z"
}

通用参数

General Parameters

参数说明
--config <path>
配置文件路径(默认 ~/.cbi/config.json)
-f, --format
输出格式:json / table
-v, --verbose
显示详细信息
ParameterDescription
--config <path>
Configuration file path (default ~/.cbi/config.json)
-f, --format
Output format: json / table
-v, --verbose
Show detailed information