feat(cmd/gf): add broad matching to gf gen dao's tableEx attribute. (#4453)

Add "*" and "?" to tableEx for "gf gen dao".

The "*" will match none or some char. And the "?" only match one char.

Co-authored-by: hailaz <739476267@qq.com>
This commit is contained in:
Hunk Zhu
2025-09-30 11:27:03 +08:00
committed by GitHub
parent 0f6d47c7a8
commit 7b373446dc

View File

@ -190,8 +190,29 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) {
// Table excluding.
if in.TablesEx != "" {
array := garray.NewStrArrayFrom(tableNames)
for _, v := range gstr.SplitAndTrim(in.TablesEx, ",") {
array.RemoveValue(v)
for _, p := range gstr.SplitAndTrim(in.TablesEx, ",") {
if gstr.Contains(p, "*") || gstr.Contains(p, "?") {
p = gstr.ReplaceByMap(p, map[string]string{
"\r": "",
"\n": "",
})
p = gstr.ReplaceByMap(p, map[string]string{
"*": "\r",
"?": "\n",
})
p = gregex.Quote(p)
p = gstr.ReplaceByMap(p, map[string]string{
"\r": ".*",
"\n": ".",
})
for _, v := range array.Slice() {
if gregex.IsMatchString(p, v) {
array.RemoveValue(v)
}
}
} else {
array.RemoveValue(p)
}
}
tableNames = array.Slice()
}