跳转到内容

cnb-rs repo gitignore

cnb-rs repo gitignore <subcommand> [flags]

从 CNB 镜像仓库拉取 .gitignore 模板。等价于 gh repo gitignore,但数据源是 CNB (默认 wwvo/cnb-rs/gitignore-templates),走 CNB 自家网络,无需访问 api.github.com

子命令

  • list:列出仓库内所有 .gitignore 模板名
  • view <name>:显示指定模板内容(如 view NodeNode.gitignore

数据源

默认拉 wwvo/cnb-rs/gitignore-templates。仓库约定在 templates/ 子目录下放 <Name>.gitignore 文件(如 templates/Node.gitignoretemplates/Rust.gitignore),命令在 list 时 自动剥掉 .gitignore 后缀展示。

仓库根目录留给 README.md / seed.py / .gitignore 等脚手架文件,不会干扰模板列表。

可在 ~/.cnb/config.toml 覆盖:

toml
[templates]
gitignore_repo = "your-org/your-gitignore-templates"

也可以临时通过 --repo 覆盖单次调用:

bash
cnb-rs repo gitignore list --repo other-org/templates

示例

bash
# 列出所有可用模板
$ cnb-rs repo gitignore list
来源:wwvo/cnb-rs/gitignore-templates 42 个模板
Node
Python
Rust
...

# 显示某个模板(输出到 stdout,可重定向到文件)
$ cnb-rs repo gitignore view Node
# Logs
logs
*.log
...

# 一步生成 .gitignore
$ cnb-rs repo gitignore view Rust > .gitignore

# 指定其他分支
$ cnb-rs repo gitignore view Node --ref develop

# JSON 输出
$ cnb-rs repo gitignore list --json

选项

list / view 通用:

  • --repo <REPO>: 临时覆盖模板仓库 path
  • --ref <REF>: 指定分支或 commit(默认仓库默认分支)

view 专属:

  • <name>: 模板名(不带 .gitignore 后缀;带了也兼容自动剥掉)
  • --json: 输出 {"name": "...", "path": "...", "repo": "...", "content": "..."} 而非裸文本

API

步骤API方法
列模板${CNB_API_ENDPOINT}/{repo}/-/git/contents/templatesGET
查看模板${CNB_API_ENDPOINT}/{repo}/-/git/contents/templates/{name}.gitignoreGET

两端都走 generated 的 git::get_content(查看二进制调用同样的 base64 解码路径,复用 download 命令逻辑)。

另请参阅

Released under the MIT License.