cnb-rs repo license
cnb-rs repo license <subcommand> [flags]从 CNB 镜像仓库拉取开源许可证模板。等价于 gh repo license,但数据源是 CNB (默认 wwvo/cnb-rs/license-templates),走 CNB 自家网络,无需访问 api.github.com。
子命令
list:列出仓库内所有 license 模板名view <name>:显示指定 license 内容(如view MIT拉MIT.txt)
数据源
默认拉 wwvo/cnb-rs/license-templates。仓库约定在 templates/ 子目录下放 <SPDX-ID>.txt 文件(如 templates/MIT.txt、templates/Apache-2.0.txt、templates/GPL-3.0.txt),命令在 list 时自动剥掉 .txt 后缀展示。
仓库根目录留给 README.md / seed.py / .gitignore 等脚手架文件,不会干扰 license 列表。
可在 ~/.cnb/config.toml 覆盖:
toml
[templates]
license_repo = "your-org/your-license-templates"也可以临时通过 --repo 覆盖单次调用:
bash
cnb-rs repo license list --repo other-org/templates示例
bash
# 列出所有可用 license(默认 47 个)
$ cnb-rs repo license list
来源:wwvo/cnb-rs/license-templates 共 47 个 license
0BSD
AFL-3.0
AGPL-3.0
Apache-2.0
...
# 只列 featured 推荐项(与 `gh repo license list --featured` 对齐)
$ cnb-rs repo license list --featured
来源:wwvo/cnb-rs/license-templates 共 3 个 license(featured 过滤后 3/47)
Apache-2.0
GPL-3.0
MIT
# 显示某个 license(输出到 stdout,可重定向到文件)
$ cnb-rs repo license view MIT
MIT License
Copyright (c) ...
# JSON 输出(list 是数组,view 是带 spdx_id/path/repo/content 的对象)
$ cnb-rs repo license list --featured --json
$ cnb-rs repo license view MIT --json
# 一步生成 LICENSE 文件
$ cnb-rs repo license view Apache-2.0 > LICENSE
# 指定其他分支
$ cnb-rs repo license view MIT --ref develop选项
list / view 通用:
--repo <REPO>: 临时覆盖模板仓库 path--ref <REF>: 指定分支或 commit(默认仓库默认分支)
list 专属:
--featured: 只列 featured 的 license(拉templates/.metadata.json过滤,metadata 缺失时 fallback 为列全部 + warn)
view 专属:
<name>: SPDX ID(如MIT/Apache-2.0;不带.txt后缀;带了也兼容自动剥掉)--json: 输出{"spdx_id": "...", "path": "...", "repo": "...", "content": "..."}而非裸文本
API
| 步骤 | API | 方法 |
|---|---|---|
| 列 license | ${CNB_API_ENDPOINT}/{repo}/-/git/contents/templates | GET |
| 查看 license 内容 | ${CNB_API_ENDPOINT}/{repo}/-/git/contents/templates/{spdx_id}.txt | GET |
| 拉 featured 元数据 | ${CNB_API_ENDPOINT}/{repo}/-/git/contents/templates/.metadata.json | GET |
三端都走 generated 的 git::get_content(查看二进制 / 元数据都复用同样的 base64 解码逻辑)。.metadata.json 由模板仓库的 seed.py 在解析上游 frontmatter 时生成,schema 见模板仓库 README。
另请参阅
- cnb-rs repo
- cnb-rs repo gitignore
- cnb-rs repo edit(设置仓库 license 字段)