CLI 参考

cast 命令行界面的完整参考文档。

目录


安装

pip install castops

要求:Python 3.9 或更高版本。

安装完成后,cast 命令即可在您的 PATH 中使用。

cast --help

全局选项

Options:
  --help    Show help message and exit.

不带参数运行 cast 将显示帮助信息。


命令

cast init

在当前目录中初始化 DevSecOps 流水线。

语法

cast init [OPTIONS]

说明

将生产就绪的 GitHub Actions 工作流写入 .github/workflows/devsecops.yml

该命令执行以下步骤:

  1. 从标记文件检测项目类型(或使用 --type 指定)
  2. 检查工作流文件是否已存在
  3. 读取对应项目类型的内嵌模板
  4. .github/workflows/ 不存在则创建该目录
  5. 写入工作流文件

选项

选项 缩写 类型 默认值 说明
--force -f 标志 false 覆盖已存在的工作流文件
--type -t 字符串 (自动检测) 项目类型:python
--help 显示帮助并退出

示例

自动检测项目类型:

cd my-python-project
cast init

输出:

╭──────────────────────────────────────────────────╮
│ CAST — CI/CD Automation & Security Toolkit        │
╰──────────────────────────────────────────────────╯
Detected project type: python
Downloading template... done

✓ Created .github/workflows/devsecops.yml

Commit and push to activate your DevSecOps pipeline:
  git add .github/workflows/devsecops.yml
  git commit -m 'ci: add CAST DevSecOps pipeline'
  git push

手动指定项目类型:

cast init --type python

覆盖已存在的工作流:

cast init --force
# or
cast init -f

自动检测逻辑

CAST 扫描当前目录中的以下标记文件:

项目类型 标记文件 状态
python pyproject.toml, requirements.txt, setup.py, setup.cfg ✅ 可用
nodejs package.json 🔜 即将推出
go go.mod 🔜 即将推出

第一个匹配的项目类型优先生效。若未找到标记文件,cast init 将退出并提示使用 --type

错误情况

错误 原因 解决方法
Could not detect project type. 未找到标记文件 使用 --type python
Workflow already exists .github/workflows/devsecops.yml 已存在 使用 --force 覆盖
Unsupported project type 类型不被识别 使用受支持的类型
nodejs support is coming soon 该技术栈尚未可用 目前请使用 python

cast version

显示已安装的 castops 版本。

语法

cast version

说明

从已安装的包元数据中读取版本号并输出。

示例

cast version
# cast 0.1.0

退出码

退出码 含义
0 成功
1 错误(检测失败、不支持的类型、文件已存在、模板错误)

环境变量

cast CLI 不直接读取任何环境变量。生成的工作流所需的环境变量(如 SEMGREP_APP_TOKEN)应配置为 GitHub Actions 密钥,而非本地环境变量。