feat: 增强命令帮助文档,添加详细说明和示例

This commit is contained in:
Rogee
2025-09-12 10:33:57 +08:00
parent a96df4d628
commit ee15e0932a
17 changed files with 217 additions and 52 deletions

View File

@@ -15,12 +15,31 @@ import (
)
func CommandGenRoute(root *cobra.Command) {
cmd := &cobra.Command{
Use: "route",
Short: "generate routes",
RunE: commandGenRouteE,
PostRunE: commandGenProviderE,
}
cmd := &cobra.Command{
Use: "route",
Short: "generate routes",
Long: `扫描项目控制器,解析注释生成 routes.gen.go。
用法与规则:
- 扫描根目录通过 --path 指定(默认 CWD会在 <path>/app/http 下递归搜索。
- 使用注释定义路由与参数绑定:
- @Router <path> [<method>] 例如:@Router /users/:id [get]
- @Bind <name> (<position>) key(<key>) [model(<field[:field_type]>)]
- position 枚举path|query|body|header|cookie|local|file
- model() 形式model() 默认 id:intmodel(id) 默认 intmodel(id:int) 显式类型
参数位置与类型建议:
- path标量或结合 model() 从路径值加载模型
- query/header标量或结构体
- cookie标量string 有快捷写法
- body结构体或标量
- file固定 multipart.FileHeader
- local任意类型上下文本地值
说明:生成完成后会自动运行 gen provider 以补全依赖注入。`,
RunE: commandGenRouteE,
PostRunE: commandGenProviderE,
}
cmd.Flags().String("path", ".", "Base path to scan (defaults to CWD)")