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

@@ -5,6 +5,7 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"text/template"
"github.com/samber/lo"
@@ -18,8 +19,17 @@ func CommandNewJob(root *cobra.Command) {
cmd := &cobra.Command{
Use: "job",
Short: "创建新的 job",
Args: cobra.ExactArgs(1),
RunE: commandNewJobE,
Long: `在 app/jobs 下渲染创建任务模板文件。
行为:
- 名称转换:输入名的 Snake 与 Pascal 形式分别用于文件名与导出名
- 输出到 app/jobs/<snake>.go
- --dry-run 仅打印渲染与写入动作;--dir 指定输出基目录(默认 .
示例:
atomctl new job SendDailyReport`,
Args: cobra.ExactArgs(1),
RunE: commandNewJobE,
}
root.AddCommand(cmd)
@@ -63,6 +73,10 @@ func commandNewJobE(cmd *cobra.Command, args []string) error {
return nil
}
if strings.HasPrefix(snakeName, "job_") {
snakeName = "job_" + snakeName
}
filePath := filepath.Join(basePath, snakeName+".go")
tmpl, err := template.ParseFS(templates.Jobs, path)
if err != nil {