refactor file|path (#1409)
Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/template"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/format"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
// Context defines the model generation data what they needs
|
||||
@@ -39,7 +40,7 @@ func generateModel(ctx *Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
text, err := util.LoadTemplate(category, modelTemplateFile, template.Text)
|
||||
text, err := pathx.LoadTemplate(category, modelTemplateFile, template.Text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -58,7 +59,7 @@ func generateModel(ctx *Context) error {
|
||||
}
|
||||
|
||||
func generateError(ctx *Context) error {
|
||||
text, err := util.LoadTemplate(category, errTemplateFile, template.Error)
|
||||
text, err := pathx.LoadTemplate(category, errTemplateFile, template.Error)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
var testTypes = `
|
||||
@@ -19,7 +19,7 @@ func TestDo(t *testing.T) {
|
||||
cfg, err := config.NewConfig(config.DefaultFormat)
|
||||
assert.Nil(t, err)
|
||||
|
||||
tempDir := util.MustTempDir()
|
||||
tempDir := pathx.MustTempDir()
|
||||
typesfile := filepath.Join(tempDir, "types.go")
|
||||
err = ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/template"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -26,12 +26,12 @@ func Category() string {
|
||||
|
||||
// Clean cleans the mongo templates.
|
||||
func Clean() error {
|
||||
return util.Clean(category)
|
||||
return pathx.Clean(category)
|
||||
}
|
||||
|
||||
// Templates initializes the mongo templates.
|
||||
func Templates(_ *cli.Context) error {
|
||||
return util.InitTemplates(category, templates)
|
||||
return pathx.InitTemplates(category, templates)
|
||||
}
|
||||
|
||||
// RevertTemplate reverts the given template.
|
||||
@@ -41,7 +41,7 @@ func RevertTemplate(name string) error {
|
||||
return fmt.Errorf("%s: no such file name", name)
|
||||
}
|
||||
|
||||
return util.CreateTemplate(category, name, content)
|
||||
return pathx.CreateTemplate(category, name, content)
|
||||
}
|
||||
|
||||
// Update cleans and updates the templates.
|
||||
@@ -51,5 +51,5 @@ func Update() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return util.InitTemplates(category, templates)
|
||||
return pathx.InitTemplates(category, templates)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/generate"
|
||||
file "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ func Action(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
if len(home) > 0 {
|
||||
file.RegisterGoctlHome(home)
|
||||
pathx.RegisterGoctlHome(home)
|
||||
}
|
||||
|
||||
if len(tp) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user