@@ -43,6 +43,7 @@ type Trimmer struct {
4343 forceTrimming bool
4444 preservedStructsMap map [string ]struct {}
4545 disablePreserveComment bool
46+ trimEnums bool
4647 structsTrimmed int
4748 fieldsTrimmed int
4849 extServices []* parser.Service
@@ -60,6 +61,7 @@ type TrimASTArg struct {
6061 PreserveStructs []string
6162 PreservedFiles []string
6263 IncludeDirs []string
64+ TrimEnums * bool
6365}
6466
6567type TrimResultInfo struct {
@@ -106,6 +108,9 @@ func TrimAST(arg *TrimASTArg) (trimResultInfo *TrimResultInfo, err error) {
106108 if arg .DisablePreserveComment == nil && cfg .DisablePreserveComment != nil {
107109 arg .DisablePreserveComment = cfg .DisablePreserveComment
108110 }
111+ if arg .TrimEnums == nil && cfg .TrimEnums != nil {
112+ arg .TrimEnums = cfg .TrimEnums
113+ }
109114 if len (preservedStructs ) == 0 {
110115 preservedStructs = cfg .PreservedStructs
111116 }
@@ -127,11 +132,15 @@ func TrimAST(arg *TrimASTArg) (trimResultInfo *TrimResultInfo, err error) {
127132 if arg .DisablePreserveComment != nil {
128133 disablePreserveComment = * arg .DisablePreserveComment
129134 }
130- return doTrimAST (arg .Ast , arg .TrimMethods , forceTrim , matchGoName , disablePreserveComment , preservedStructs , preservedFiles )
135+ trimEnums := false
136+ if arg .TrimEnums != nil {
137+ trimEnums = * arg .TrimEnums
138+ }
139+ return doTrimAST (arg .Ast , arg .TrimMethods , forceTrim , matchGoName , disablePreserveComment , trimEnums , preservedStructs , preservedFiles )
131140}
132141
133142// doTrimAST trim the single AST, pass method names if -m specified
134- func doTrimAST (ast * parser.Thrift , trimMethods []string , forceTrimming , matchGoName , disablePreserveComment bool , preservedStructs , preserveFiles []string ) (
143+ func doTrimAST (ast * parser.Thrift , trimMethods []string , forceTrimming , matchGoName , disablePreserveComment , trimEnums bool , preservedStructs , preserveFiles []string ) (
135144 trimResultInfo * TrimResultInfo , err error ) {
136145 trimmer , err := newTrimmer (nil , "" )
137146 if err != nil {
@@ -142,6 +151,7 @@ func doTrimAST(ast *parser.Thrift, trimMethods []string, forceTrimming, matchGoN
142151 trimmer .trimMethodValid = make ([]bool , len (trimMethods ))
143152 trimmer .forceTrimming = forceTrimming
144153 trimmer .matchGoName = matchGoName
154+ trimmer .trimEnums = trimEnums
145155 if len (ast .Services ) > 0 {
146156 for i , method := range trimMethods {
147157 parts := strings .Split (method , "." )
@@ -229,6 +239,9 @@ func Trim(files, includeDir []string, outDir string) error {
229239
230240func (t * Trimmer ) countStructs (ast * parser.Thrift ) {
231241 t .structsTrimmed += len (ast .Structs ) + len (ast .Includes ) + len (ast .Services ) + len (ast .Unions ) + len (ast .Exceptions )
242+ if t .trimEnums {
243+ t .structsTrimmed += len (ast .Enums )
244+ }
232245 for _ , v := range ast .Structs {
233246 t .fieldsTrimmed += len (v .Fields )
234247 }
0 commit comments