Skip to content

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 指导材料化到项目中。