Renamed new flags name '-tables', '-views', and '-enums'.

This commit is contained in:
SanjaiyKumar 2025-06-24 14:09:30 +05:30
parent dbfcec7fbe
commit 85fdfb01b3
4 changed files with 60 additions and 84 deletions

View file

@ -94,9 +94,9 @@ func init() {
flag.StringVar(&viewPkg, "rel-view-path", "view", "Relative path for the View files package from the destination directory.") flag.StringVar(&viewPkg, "rel-view-path", "view", "Relative path for the View files package from the destination directory.")
flag.StringVar(&enumPkg, "rel-enum-path", "enum", "Relative path for the Enum files package from the destination directory.") flag.StringVar(&enumPkg, "rel-enum-path", "enum", "Relative path for the Enum files package from the destination directory.")
flag.StringVar(&allowTables, "allow-tables", "", `Comma-separated list of tables to allow. Takes precedence over --ignore-tables flag.`) flag.StringVar(&allowTables, "tables", "", `Comma-separated list of tables to allow.`)
flag.StringVar(&allowViews, "allow-views", "", `Comma-separated list of views to allow. Takes precedence over --ignore-views flag.`) flag.StringVar(&allowViews, "views", "", `Comma-separated list of views to allow.`)
flag.StringVar(&allowEnums, "allow-enums", "", `Comma-separated list of enums to allow. Takes precedence over --ignore-enums flag.`) flag.StringVar(&allowEnums, "enums", "", `Comma-separated list of enums to allow.`)
} }
func main() { func main() {
@ -108,9 +108,9 @@ func main() {
} }
source := getSource() source := getSource()
tablesFilter := createTemplateFilter(ignoreTables, allowTables) tablesFilter := createTemplateFilter(ignoreTables, allowTables, "tables")
viewsFilter := createTemplateFilter(ignoreViews, allowViews) viewsFilter := createTemplateFilter(ignoreViews, allowViews, "views")
enumsFilter := createTemplateFilter(ignoreEnums, allowEnums) enumsFilter := createTemplateFilter(ignoreEnums, allowEnums, "enums")
var err error var err error
@ -197,8 +197,8 @@ func usage() {
"path", "path",
"ignore-tables", "ignore-views", "ignore-enums", "ignore-tables", "ignore-views", "ignore-enums",
"skip-model", "skip-sql-builder", "skip-model", "skip-sql-builder",
"rel-model-path", "rel-table-path", "rel-view-path", "rel-enum-path", "allow-tables", "allow-views", "rel-model-path", "rel-table-path", "rel-view-path", "rel-enum-path", "tables", "views",
"allow-enums", "enums",
} }
for _, name := range order { for _, name := range order {
@ -311,7 +311,11 @@ func genTemplate(dialect jet.Dialect, tablesFilter, viewsFilter, enumsFilter tem
}) })
} }
func createTemplateFilter(ignoreList, allowList string) templateFilter { func createTemplateFilter(ignoreList, allowList, filterType string) templateFilter {
if ignoreList != "" && allowList != "" {
printErrorAndExit(fmt.Sprintf("ERROR: cannot use both -%s and -ignore-%s flags simultaneously. Please specify only one option.", filterType, filterType))
}
if allowList != "" { if allowList != "" {
return templateFilter{ return templateFilter{
names: parseList(allowList), names: parseList(allowList),

View file

@ -1,6 +1,7 @@
package mysql package mysql
import ( import (
"bytes"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -1012,9 +1013,9 @@ func TestAllowTablesViewsEnums(t *testing.T) {
name: "with dsn", name: "with dsn",
args: []string{ args: []string{
"-dsn=mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds"), "-dsn=mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds"),
"-allow-tables=actor,ADDRESS,Category, city ,country,staff,store,rental", "-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
"-allow-views=actor_info,CUSTomER_LIST, film_list", "-views=actor_info,CUSTomER_LIST, film_list",
"-allow-enums=film_list_rating,film_rating", "-enums=film_list_rating,film_rating",
"-path=" + genTestDir3, "-path=" + genTestDir3,
}, },
}, },
@ -1027,9 +1028,9 @@ func TestAllowTablesViewsEnums(t *testing.T) {
"-port=" + strconv.Itoa(dbconfig.MySQLPort), "-port=" + strconv.Itoa(dbconfig.MySQLPort),
"-user=" + dbconfig.MySQLUser, "-user=" + dbconfig.MySQLUser,
"-password=" + dbconfig.MySQLPassword, "-password=" + dbconfig.MySQLPassword,
"-allow-tables=actor,ADDRESS,Category, city ,country,staff,store,rental", "-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
"-allow-views=actor_info,CUSTomER_LIST, film_list", "-views=actor_info,CUSTomER_LIST, film_list",
"-allow-enums=film_list_rating,film_rating", "-enums=film_list_rating,film_rating",
"-path=" + genTestDir3, "-path=" + genTestDir3,
}, },
}, },
@ -1069,9 +1070,9 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
name: "with dsn", name: "with dsn",
args: []string{ args: []string{
"-dsn=mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds"), "-dsn=mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds"),
"-allow-tables=actor,ADDRESS,Category, city ,country,staff,store,rental", "-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
"-allow-views=actor_info,CUSTomER_LIST, film_list", "-views=actor_info,CUSTomER_LIST, film_list",
"-allow-enums=film_list_rating,film_rating", "-enums=film_list_rating,film_rating",
"-ignore-tables=actor,ADDRESS,store,rental", "-ignore-tables=actor,ADDRESS,store,rental",
"-ignore-views=film_list", "-ignore-views=film_list",
"-ignore-enums=film_rating", "-ignore-enums=film_rating",
@ -1087,9 +1088,9 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
"-port=" + strconv.Itoa(dbconfig.MySQLPort), "-port=" + strconv.Itoa(dbconfig.MySQLPort),
"-user=" + dbconfig.MySQLUser, "-user=" + dbconfig.MySQLUser,
"-password=" + dbconfig.MySQLPassword, "-password=" + dbconfig.MySQLPassword,
"-allow-tables=actor,ADDRESS,Category, city ,country,staff,store,rental", "-tables=actor,ADDRESS,Category, city ,country,staff,store,rental",
"-allow-views=actor_info,CUSTomER_LIST, film_list", "-views=actor_info,CUSTomER_LIST, film_list",
"-allow-enums=film_list_rating,film_rating", "-enums=film_list_rating,film_rating",
"-ignore-tables=actor,ADDRESS,store,rental", "-ignore-tables=actor,ADDRESS,store,rental",
"-ignore-views=film_list", "-ignore-views=film_list",
"-ignore-enums=film_rating", "-ignore-enums=film_rating",
@ -1102,23 +1103,16 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := exec.Command("jet", tt.args...) cmd := exec.Command("jet", tt.args...)
var stdOut bytes.Buffer
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout cmd.Stdout = &stdOut
err := cmd.Run() err := cmd.Run()
require.NoError(t, err) require.Error(t, err)
require.Equal(t, "exit status 1", err.Error())
testutils.AssertFileNamesEqual(t, genTestDir3+"/dvds/table", "category.go", "actor.go", "address.go", stdOutput := stdOut.String()
"city.go", "country.go", "staff.go", "store.go", "rental.go", "table_use_schema.go") require.Contains(t, stdOutput, "ERROR: cannot use both -tables and -ignore-tables flags simultaneously. Please specify only one option.")
testutils.AssertFileNamesEqual(t, genTestDir3+"/dvds/view", "actor_info.go", "customer_list.go",
"film_list.go", "view_use_schema.go")
testutils.AssertFileNamesEqual(t, genTestDir3+"/dvds/enum", "film_list_rating.go", "film_rating.go")
testutils.AssertFileNamesEqual(t, genTestDir3+"/dvds/model", "category.go", "actor.go", "address.go",
"city.go", "country.go", "staff.go", "store.go", "rental.go", "actor_info.go",
"customer_list.go", "film_list.go", "film_list_rating.go", "film_rating.go")
}) })
} }
} }

View file

@ -1,6 +1,7 @@
package postgres package postgres
import ( import (
"bytes"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -1395,9 +1396,9 @@ func TestAllowTablesViewsEnums(t *testing.T) {
args: []string{ args: []string{
"-dsn=" + defaultDSN(), "-dsn=" + defaultDSN(),
"-schema=dvds", "-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,", "-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list", "-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating", "-enums=mpaa_rating",
"-path=" + genTestDir2, "-path=" + genTestDir2,
}, },
}, },
@ -1411,9 +1412,9 @@ func TestAllowTablesViewsEnums(t *testing.T) {
"-password=jet", "-password=jet",
"-dbname=jetdb", "-dbname=jetdb",
"-schema=dvds", "-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,", "-tables=actor,ADDRESS,country, Film , cITY,",
"-allow-views=Actor_info, FILM_LIST ,staff_list", "-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating", "-enums=mpaa_rating",
"-path=" + genTestDir2, "-path=" + genTestDir2,
}, },
}, },
@ -1451,7 +1452,7 @@ func TestAllowTablesViewsEnums(t *testing.T) {
} }
} }
func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) { func TestAllowAndIgnoreEnums(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args []string args []string
@ -1461,11 +1462,7 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
args: []string{ args: []string{
"-dsn=" + defaultDSN(), "-dsn=" + defaultDSN(),
"-schema=dvds", "-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,", "-enums=mpaa_rating",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-ignore-tables=ADDRESS,country, Film",
"-ignore-views=FILM_LIST",
"-ignore-enums=mpaa_rating", "-ignore-enums=mpaa_rating",
"-path=" + genTestDir2, "-path=" + genTestDir2,
}, },
@ -1480,11 +1477,7 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
"-password=jet", "-password=jet",
"-dbname=jetdb", "-dbname=jetdb",
"-schema=dvds", "-schema=dvds",
"-allow-tables=actor,ADDRESS,country, Film , cITY,", "-enums=mpaa_rating",
"-allow-views=Actor_info, FILM_LIST ,staff_list",
"-allow-enums=mpaa_rating",
"-ignore-tables=ADDRESS,country, Film",
"-ignore-views=FILM_LIST",
"-ignore-enums=mpaa_rating", "-ignore-enums=mpaa_rating",
"-path=" + genTestDir2, "-path=" + genTestDir2,
}, },
@ -1499,26 +1492,16 @@ func TestAllowAndIgnoreTablesViewsEnums(t *testing.T) {
cmd := exec.Command("jet", tt.args...) cmd := exec.Command("jet", tt.args...)
fmt.Println(cmd.Args) fmt.Println(cmd.Args)
var stdOut bytes.Buffer
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout cmd.Stdout = &stdOut
err = cmd.Run() err = cmd.Run()
require.NoError(t, err) require.Error(t, err)
require.Equal(t, "exit status 1", err.Error())
// Table SQL Builder files stdOutput := stdOut.String()
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/table", "actor.go", "address.go", require.Contains(t, stdOutput, "ERROR: cannot use both -enums and -ignore-enums flags simultaneously. Please specify only one option.")
"country.go", "film.go", "city.go", "table_use_schema.go")
// View SQL Builder files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/view", "actor_info.go", "film_list.go",
"staff_list.go", "view_use_schema.go")
// Enums SQL Builder files
file.Exists(t, "./.gentestdata2/jetdb/dvds/enum", "mpaa_rating.go")
// Model files
testutils.AssertFileNamesEqual(t, "./.gentestdata2/jetdb/dvds/model", "actor.go", "address.go",
"country.go", "film.go", "city.go", "actor_info.go", "film_list.go", "staff_list.go", "mpaa_rating.go")
}) })
} }
} }

View file

@ -1,6 +1,7 @@
package sqlite package sqlite
import ( import (
"bytes"
"os" "os"
"os/exec" "os/exec"
"reflect" "reflect"
@ -432,8 +433,8 @@ func TestAllowTablesEnums(t *testing.T) {
cmd := exec.Command("jet", cmd := exec.Command("jet",
"-source=SQLite", "-source=SQLite",
"-dsn=file://"+testDatabaseFilePath, "-dsn=file://"+testDatabaseFilePath,
"-allow-tables=actor,Address,CATEGORY , city ,film,rental,store", "-tables=actor,Address,CATEGORY , city ,film,rental,store",
"-allow-views=customer_list, film_list,STAFF_LIst", "-views=customer_list, film_list,STAFF_LIst",
"-path="+genDestDir) "-path="+genDestDir)
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -452,28 +453,22 @@ func TestAllowTablesEnums(t *testing.T) {
"film.go", "rental.go", "store.go", "customer_list.go", "film_list.go", "staff_list.go") "film.go", "rental.go", "store.go", "customer_list.go", "film_list.go", "staff_list.go")
} }
func TestAllowAndIgnoreTablesEnums(t *testing.T) { func TestAllowAndIgnoreViews(t *testing.T) {
cmd := exec.Command("jet", cmd := exec.Command("jet",
"-source=SQLite", "-source=SQLite",
"-dsn=file://"+testDatabaseFilePath, "-dsn=file://"+testDatabaseFilePath,
"-allow-tables=actor,Address,CATEGORY , city ,film,rental,store", "-views=customer_list, film_list,STAFF_LIst",
"-allow-views=customer_list, film_list,STAFF_LIst",
"-ignore-tables=actor,CATEGORY ,store",
"-ignore-views=customer_list", "-ignore-views=customer_list",
"-path="+genDestDir) "-path="+genDestDir)
var stdOut bytes.Buffer
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout cmd.Stdout = &stdOut
err := cmd.Run() err := cmd.Run()
require.NoError(t, err) require.Error(t, err)
require.Equal(t, "exit status 1", err.Error())
testutils.AssertFileNamesEqual(t, genDestDir+"/table", "actor.go", "address.go", "category.go", "city.go", stdOutput := stdOut.String()
"film.go", "rental.go", "store.go", "table_use_schema.go") require.Contains(t, stdOutput, "ERROR: cannot use both -views and -ignore-views flags simultaneously. Please specify only one option.")
testutils.AssertFileNamesEqual(t, genDestDir+"/view", "customer_list.go", "film_list.go", "staff_list.go",
"view_use_schema.go")
testutils.AssertFileNamesEqual(t, genDestDir+"/model", "actor.go", "address.go", "category.go", "city.go",
"film.go", "rental.go", "store.go", "customer_list.go", "film_list.go", "staff_list.go")
} }