feat: remove module command
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
pgDatabase "go.ipao.vip/atomctl/pkg/postgres"
|
||||
"go.ipao.vip/atomctl/pkg/utils/gomod"
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
"github.com/go-jet/jet/v2/generator/postgres"
|
||||
"github.com/go-jet/jet/v2/generator/template"
|
||||
@@ -19,6 +17,9 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
astModel "go.ipao.vip/atomctl/pkg/ast/model"
|
||||
pgDatabase "go.ipao.vip/atomctl/pkg/postgres"
|
||||
"go.ipao.vip/atomctl/pkg/utils/gomod"
|
||||
)
|
||||
|
||||
func CommandGenModel(root *cobra.Command) {
|
||||
@@ -68,6 +69,8 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
|
||||
"bool",
|
||||
}
|
||||
|
||||
generatedTables := []string{}
|
||||
|
||||
err = postgres.GenerateDSN(
|
||||
dbConf.DSN(),
|
||||
dbConf.Schema,
|
||||
@@ -108,6 +111,8 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
|
||||
return tbl
|
||||
}
|
||||
|
||||
generatedTables = append(generatedTables, table.Name)
|
||||
|
||||
return tbl.UseField(func(column metadata.Column) template.TableModelField {
|
||||
defaultTableModelField := template.DefaultTableModelField(column)
|
||||
defaultTableModelField = defaultTableModelField.UseTags(fmt.Sprintf(`json:"%s"`, column.Name))
|
||||
@@ -164,6 +169,5 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
|
||||
if err := os.Rename(dataPath, "database/schemas"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return astModel.Generate(generatedTables)
|
||||
}
|
||||
|
||||
@@ -4,21 +4,21 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"go.ipao.vip/atomctl/pkg/ast/route"
|
||||
"go.ipao.vip/atomctl/pkg/utils/gomod"
|
||||
"github.com/samber/lo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"go.ipao.vip/atomctl/pkg/ast/route"
|
||||
"go.ipao.vip/atomctl/pkg/utils/gomod"
|
||||
)
|
||||
|
||||
func CommandGenRoute(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "route",
|
||||
Short: "generate routes",
|
||||
RunE: commandGenRouteE,
|
||||
PostRunE: commandGenProviderE,
|
||||
Use: "route",
|
||||
Short: "generate routes",
|
||||
RunE: commandGenRouteE,
|
||||
// PostRunE: commandGenProviderE,
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
@@ -51,13 +51,20 @@ func commandGenRouteE(cmd *cobra.Command, args []string) error {
|
||||
log.Fatal("modules dir not exist, ", modulePath)
|
||||
}
|
||||
|
||||
controllerPattern := regexp.MustCompile(`controller(_?\w+)?\.go`)
|
||||
// controllerPattern := regexp.MustCompile(`controller(_?\w+)?\.go`)
|
||||
err = filepath.WalkDir(modulePath, func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !controllerPattern.MatchString(d.Name()) {
|
||||
// if !controllerPattern.MatchString(d.Name()) {
|
||||
// return nil
|
||||
// }
|
||||
if strings.HasSuffix(path, ".gen.go") {
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.HasSuffix(path, "_test.go") {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func CommandInit(root *cobra.Command) {
|
||||
|
||||
cmds := []func(*cobra.Command){
|
||||
CommandNewProject,
|
||||
CommandNewModule,
|
||||
// deprecate CommandNewModule,
|
||||
CommandNewProvider,
|
||||
CommandNewEvent,
|
||||
CommandNewJob,
|
||||
|
||||
Reference in New Issue
Block a user