CLI 命令
这页给出 Targo CLI 的核心工作流参考。
主要命令
| 命令 | 用途 |
|---|---|
targo init | 初始化或刷新声明与项目状态 |
targo install | 安装 Go 包并生成类型声明 |
targo build | 编译为 Go |
targo check | 仅做检查,不生成代码 |
targo run | 构建并运行 |
targo test | 编译并运行测试 |
targo bind | 为 Go 包生成声明 |
targo generate | 执行生成流程 |
targo agents-md | 生成或刷新 AGENTS.md 与 .targo-docs/ |
安装 Go 包
targo install 封装了 go get,并自动生成 .d.ts 声明,使你可以从 Targo 源码中导入 Go 包。
bash
# 安装单个包
targo install github.com/fatih/color
# 安装一个包及其所有子包(递归绑定)
targo install github.com/cloudwego/kitex/...
# 或使用 --recursive 标志
targo install --recursive github.com/cloudwego/kitex
# 安装 go.mod 中的所有依赖(不带参数)
targo install底层机制:
targo install <pkg>运行go get <pkg>,然后调用 binder 生成.d.ts声明/...后缀(或--recursive)告诉 binder 为模块中的所有子包生成声明,而不仅仅是根包- 不带参数时,读取
go.mod并为所有列出的依赖安装声明 - 标准库包使用预打包的声明——直接
import即可,缺失时运行targo init
常见工作流
第一次进入项目
bash
targo init
targo check
targo build添加新 Go 依赖后
bash
targo install github.com/some/package
targo check改依赖或导入后
bash
targo init
targo check测试迭代
bash
targo test --run <pattern>
targo test --bench <pattern>说明:
--run直接映射到go test -run=<pattern>。--bench直接映射到go test -bench=<pattern>。- 两个标志都使用 Go 测试正则语义,不是 shell glob。
--run过滤执行哪些测试,但targo test仍会在调用go test之前进行类型检查和编译,因此它不等同于文件范围的targo check。- 运行所有基准测试:
targo test --bench .。 - 只运行基准测试而不运行普通测试,使用与 Go 相同的模式:
targo test --run '^$' --bench .。
Agent 文档刷新
bash
targo agents-md
targo agents-md --check实践规则
- 只需诊断不需要代码生成时使用
check。 - 需要生成的 Go 输出时使用
build。 - 声明相关变更后使用
init。 - 使用
agents-md将版本匹配的 agent 指导材料化到项目中。