Skip to content

Commit

Permalink
change command-line arg 'table' from string to slice type (#3707)
Browse files Browse the repository at this point in the history
  • Loading branch information
kesonan authored Nov 13, 2023
1 parent 24695bb commit 72dd273
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tools/goctl/model/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
datasourceCmdFlags.StringVar(&command.VarStringBranch, "branch")

pgDatasourceCmdFlags.StringVar(&command.VarStringURL, "url")
pgDatasourceCmdFlags.StringVarP(&command.VarStringTable, "table", "t")
pgDatasourceCmdFlags.StringSliceVarP(&command.VarStringSliceTable, "table", "t")
pgDatasourceCmdFlags.StringVarPWithDefaultValue(&command.VarStringSchema, "schema", "s", "public")
pgDatasourceCmdFlags.BoolVarP(&command.VarBoolCache, "cache", "c")
pgDatasourceCmdFlags.StringVarP(&command.VarStringDir, "dir", "d")
Expand Down
15 changes: 4 additions & 11 deletions tools/goctl/model/sql/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ var (
VarStringURL string
// VarStringSliceTable describes tables.
VarStringSliceTable []string
// VarStringTable describes a table of sql.
VarStringTable string
// VarStringStyle describes the style.
VarStringStyle string
// VarStringDatabase describes the database.
Expand Down Expand Up @@ -211,14 +209,14 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error {
schema = "public"
}

pattern := strings.TrimSpace(VarStringTable)
patterns := parseTableList(VarStringSliceTable)
cfg, err := config.NewConfig(style)
if err != nil {
return err
}
ignoreColumns := mergeColumns(VarStringSliceIgnoreColumns)

return fromPostgreSqlDataSource(url, pattern, dir, schema, cfg, cache, idea, VarBoolStrict, ignoreColumns)
return fromPostgreSqlDataSource(url, patterns, dir, schema, cfg, cache, idea, VarBoolStrict, ignoreColumns)
}

type ddlArg struct {
Expand Down Expand Up @@ -330,7 +328,7 @@ func fromMysqlDataSource(arg dataSourceArg) error {
return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
}

func fromPostgreSqlDataSource(url, pattern, dir, schema string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error {
func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error {
log := console.NewConsole(idea)
if len(url) == 0 {
log.Error("%v", "expected data source of postgresql, but nothing found")
Expand All @@ -351,12 +349,7 @@ func fromPostgreSqlDataSource(url, pattern, dir, schema string, cfg *config.Conf

matchTables := make(map[string]*model.Table)
for _, item := range tables {
match, err := filepath.Match(pattern, item)
if err != nil {
return err
}

if !match {
if !pattern.Match(item) {
continue
}

Expand Down

0 comments on commit 72dd273

Please sign in to comment.