Skip to content

Commit

Permalink
fix issue #2552
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Feb 4, 2024
1 parent 61727cf commit 117a6e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go
Expand Up @@ -276,7 +276,7 @@ func Test_Gen_Dao_Issue2552(t *testing.T) {
err = gfile.Copy(issueDirPath, path)
t.AssertNil(err)

//defer gfile.Remove(path)
defer gfile.Remove(path)

pwd := gfile.Pwd()
err = gfile.Chdir(path)
Expand Down
4 changes: 4 additions & 0 deletions cmd/gf/internal/cmd/gendao/gendao.go
Expand Up @@ -347,6 +347,10 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) {
TableNames: tableNames,
NewTableNames: newTableNames,
})

if in.Clear {
doClear(ctx, in)
}
}

func getImportPartContent(ctx context.Context, source string, isDo bool, appendImports []string) string {
Expand Down
17 changes: 11 additions & 6 deletions cmd/gf/internal/cmd/gendao/gendao_clear.go
Expand Up @@ -10,19 +10,24 @@ import (
"context"

"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

func doClear(ctx context.Context, dirPath string, force bool) {
files, err := gfile.ScanDirFile(dirPath, "*.go", true)
func doClear(ctx context.Context, in CGenDaoInput) {
filePaths, err := gfile.ScanDirFile(in.Path, "*.go", true)
if err != nil {
mlog.Fatal(err)
}
for _, file := range files {
if force || utils.IsFileDoNotEdit(file) {
if err = gfile.Remove(file); err != nil {
var allGeneratedFilePaths = make([]string, 0)
allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DaoFilePaths...)
allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DaoInternalFilePaths...)
allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.EntityFilePaths...)
allGeneratedFilePaths = append(allGeneratedFilePaths, in.generatedFilePaths.DoFilePaths...)
for _, filePath := range filePaths {
if !gstr.InArray(allGeneratedFilePaths, filePath) {
if err = gfile.Remove(filePath); err != nil {
mlog.Print(err)
}
}
Expand Down

0 comments on commit 117a6e8

Please sign in to comment.