feat: 更新模块路径为 v2,修正文档和代码中的相关引用
This commit is contained in:
@@ -7,10 +7,10 @@ import (
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
"go.ipao.vip/atomctl/pkg/utils/gomod"
|
||||
"go.ipao.vip/atomctl/templates"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cobra"
|
||||
"go.ipao.vip/atomctl/v2/pkg/utils/gomod"
|
||||
"go.ipao.vip/atomctl/v2/templates"
|
||||
)
|
||||
|
||||
// CommandNewProvider 注册 new_provider 命令
|
||||
@@ -26,14 +26,14 @@ func CommandNewJob(root *cobra.Command) {
|
||||
}
|
||||
|
||||
func commandNewJobE(cmd *cobra.Command, args []string) error {
|
||||
snakeName := lo.SnakeCase(args[0])
|
||||
camelName := lo.PascalCase(args[0])
|
||||
snakeName := lo.SnakeCase(args[0])
|
||||
camelName := lo.PascalCase(args[0])
|
||||
|
||||
// shared flags
|
||||
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
||||
baseDir, _ := cmd.Flags().GetString("dir")
|
||||
// shared flags
|
||||
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
||||
baseDir, _ := cmd.Flags().GetString("dir")
|
||||
|
||||
basePath := filepath.Join(baseDir, "app/jobs")
|
||||
basePath := filepath.Join(baseDir, "app/jobs")
|
||||
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -46,13 +46,13 @@ func commandNewJobE(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] mkdir -p %s\n", basePath)
|
||||
} else {
|
||||
if err := os.MkdirAll(basePath, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] mkdir -p %s\n", basePath)
|
||||
} else {
|
||||
if err := os.MkdirAll(basePath, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = fs.WalkDir(templates.Jobs, "jobs", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
@@ -63,27 +63,27 @@ func commandNewJobE(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
filePath := filepath.Join(basePath, snakeName+".go")
|
||||
tmpl, err := template.ParseFS(templates.Jobs, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filePath := filepath.Join(basePath, snakeName+".go")
|
||||
tmpl, err := template.ParseFS(templates.Jobs, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] render > %s\n", filePath)
|
||||
return nil
|
||||
}
|
||||
if dryRun {
|
||||
fmt.Printf("[dry-run] render > %s\n", filePath)
|
||||
return nil
|
||||
}
|
||||
|
||||
destFile, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer destFile.Close()
|
||||
destFile, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer destFile.Close()
|
||||
|
||||
return tmpl.Execute(destFile, map[string]string{
|
||||
"Name": camelName,
|
||||
"ModuleName": gomod.GetModuleName(),
|
||||
})
|
||||
return tmpl.Execute(destFile, map[string]string{
|
||||
"Name": camelName,
|
||||
"ModuleName": gomod.GetModuleName(),
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user