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(&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(&allowViews, "allow-views", "", `Comma-separated list of views to allow. Takes precedence over --ignore-views flag.`)
flag.StringVar(&allowEnums, "allow-enums", "", `Comma-separated list of enums to allow. Takes precedence over --ignore-enums flag.`)
flag.StringVar(&allowTables, "tables", "", `Comma-separated list of tables to allow.`)
flag.StringVar(&allowViews, "views", "", `Comma-separated list of views to allow.`)
flag.StringVar(&allowEnums, "enums", "", `Comma-separated list of enums to allow.`)
}
func main() {
@ -108,9 +108,9 @@ func main() {
}
source := getSource()
tablesFilter := createTemplateFilter(ignoreTables, allowTables)
viewsFilter := createTemplateFilter(ignoreViews, allowViews)
enumsFilter := createTemplateFilter(ignoreEnums, allowEnums)
tablesFilter := createTemplateFilter(ignoreTables, allowTables, "tables")
viewsFilter := createTemplateFilter(ignoreViews, allowViews, "views")
enumsFilter := createTemplateFilter(ignoreEnums, allowEnums, "enums")
var err error
@ -197,8 +197,8 @@ func usage() {
"path",
"ignore-tables", "ignore-views", "ignore-enums",
"skip-model", "skip-sql-builder",
"rel-model-path", "rel-table-path", "rel-view-path", "rel-enum-path", "allow-tables", "allow-views",
"allow-enums",
"rel-model-path", "rel-table-path", "rel-view-path", "rel-enum-path", "tables", "views",
"enums",
}
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 != "" {
return templateFilter{
names: parseList(allowList),

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package sqlite
import (
"bytes"
"os"
"os/exec"
"reflect"
@ -432,8 +433,8 @@ func TestAllowTablesEnums(t *testing.T) {
cmd := exec.Command("jet",
"-source=SQLite",
"-dsn=file://"+testDatabaseFilePath,
"-allow-tables=actor,Address,CATEGORY , city ,film,rental,store",
"-allow-views=customer_list, film_list,STAFF_LIst",
"-tables=actor,Address,CATEGORY , city ,film,rental,store",
"-views=customer_list, film_list,STAFF_LIst",
"-path="+genDestDir)
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")
}
func TestAllowAndIgnoreTablesEnums(t *testing.T) {
func TestAllowAndIgnoreViews(t *testing.T) {
cmd := exec.Command("jet",
"-source=SQLite",
"-dsn=file://"+testDatabaseFilePath,
"-allow-tables=actor,Address,CATEGORY , city ,film,rental,store",
"-allow-views=customer_list, film_list,STAFF_LIst",
"-ignore-tables=actor,CATEGORY ,store",
"-views=customer_list, film_list,STAFF_LIst",
"-ignore-views=customer_list",
"-path="+genDestDir)
var stdOut bytes.Buffer
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdout = &stdOut
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",
"film.go", "rental.go", "store.go", "table_use_schema.go")
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")
stdOutput := stdOut.String()
require.Contains(t, stdOutput, "ERROR: cannot use both -views and -ignore-views flags simultaneously. Please specify only one option.")
}