Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: add trimmer args #241

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions tool/trimmer/trim/trimmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ type Trimmer struct {
}

type TrimASTArg struct {
Ast *parser.Thrift
TrimMethods []string
Preserve *bool
MatchGoName *bool
Ast *parser.Thrift
TrimMethods []string
Preserve *bool
MatchGoName *bool
PreserveStructs []string
}

type TrimResultInfo struct {
Expand Down Expand Up @@ -80,6 +81,7 @@ func (t *TrimResultInfo) FieldTrimmedPercentage() float64 {
// TrimAST parse the cfg and trim the single AST
func TrimAST(arg *TrimASTArg) (trimResultInfo *TrimResultInfo, err error) {
var preservedStructs []string
preservedStructs = arg.PreserveStructs
if wd, err := dir_utils.Getwd(); err == nil {
cfg := ParseYamlConfig(wd)
if cfg != nil {
Expand All @@ -93,7 +95,9 @@ func TrimAST(arg *TrimASTArg) (trimResultInfo *TrimResultInfo, err error) {
if arg.MatchGoName == nil && cfg.MatchGoName != nil {
arg.MatchGoName = cfg.MatchGoName
}
preservedStructs = cfg.PreservedStructs
if len(preservedStructs) == 0 {
preservedStructs = cfg.PreservedStructs
}
}
}
forceTrim := false
Expand All @@ -108,7 +112,7 @@ func TrimAST(arg *TrimASTArg) (trimResultInfo *TrimResultInfo, err error) {
}

// doTrimAST trim the single AST, pass method names if -m specified
func doTrimAST(ast *parser.Thrift, trimMethods []string, forceTrimming bool, matchGoName bool, preservedStructs []string) (
func doTrimAST(ast *parser.Thrift, trimMethods []string, forceTrimming, matchGoName bool, preservedStructs []string) (
trimResultInfo *TrimResultInfo, err error) {
trimmer, err := newTrimmer(nil, "")
if err != nil {
Expand All @@ -128,7 +132,6 @@ func doTrimAST(ast *parser.Thrift, trimMethods []string, forceTrimming bool, mat
trimMethods[i] = ast.Services[len(ast.Services)-1].Name + "." + method
// println("please specify service name!\n -m usage: -m [service_name.method_name]")
// os.Exit(2)

}
}
trimmer.trimMethods[i], err = regexp2.Compile(trimMethods[i], 0)
Expand Down
Loading