Skip to content

Commit

Permalink
optimize: add trimmer args
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed Nov 25, 2024
1 parent c1083dc commit 7442347
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit 7442347

Please sign in to comment.