fix: create modules
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"git.ipao.vip/rogeecn/atomctl/pkg/utils/gomod"
|
||||||
"git.ipao.vip/rogeecn/atomctl/templates"
|
"git.ipao.vip/rogeecn/atomctl/templates"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -30,6 +32,16 @@ func commandNewModuleE(cmd *cobra.Command, args []string) error {
|
|||||||
return s != ""
|
return s != ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
modFile := filepath.Join(pwd, "go.mod")
|
||||||
|
if err := gomod.Parse(modFile); err != nil {
|
||||||
|
return errors.New("parse go.mod file failed")
|
||||||
|
}
|
||||||
|
|
||||||
modulePath := module[0]
|
modulePath := module[0]
|
||||||
if len(module) > 1 {
|
if len(module) > 1 {
|
||||||
modulePath = strings.Join(module, "/modules/")
|
modulePath = strings.Join(module, "/modules/")
|
||||||
@@ -49,7 +61,7 @@ func commandNewModuleE(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.MkdirAll(modulePath, os.ModePerm)
|
err = os.MkdirAll(modulePath, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -86,7 +98,8 @@ func commandNewModuleE(cmd *cobra.Command, args []string) error {
|
|||||||
defer destFile.Close()
|
defer destFile.Close()
|
||||||
|
|
||||||
return tmpl.Execute(destFile, map[string]string{
|
return tmpl.Execute(destFile, map[string]string{
|
||||||
"ModuleName": moduleName,
|
"ModuleName": moduleName,
|
||||||
|
"ProjectModule": gomod.GetModuleName(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package {{.ModuleName}}
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"backend/pkg/service/testx"
|
"{{.ProjectModule}}/pkg/service/testx"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|||||||
Reference in New Issue
Block a user