@@ -184,21 +184,9 @@ func (t *tree) displayResults(opts DumpOpts) {
184184 }
185185 }
186186
187- fmt .Printf ( "line: %s\n " , rawstr )
187+ fmt .Fprintf ( os . Stdout , "line: %s\n " , rawstr )
188188
189- skeys := make ([]string , 0 , len (t .state [tstamp ]))
190-
191- for k := range t .state [tstamp ] {
192- // there is a trick : to know if an event successfully exit the parsers, we check if it reached the pour() phase
193- // we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
194- if k == "buckets" {
195- continue
196- }
197-
198- skeys = append (skeys , k )
199- }
200-
201- sort .Strings (skeys )
189+ skeys := sortedStages (t .state [tstamp ])
202190
203191 // iterate stage
204192 var prevItem pipeline.Event
@@ -209,7 +197,7 @@ func (t *tree) displayResults(opts DumpOpts) {
209197 sep := "├"
210198 presep := "|"
211199
212- fmt .Printf ( "\t %s %s\n " , sep , stage )
200+ fmt .Fprintf ( os . Stdout , "\t %s %s\n " , sep , stage )
213201
214202 for idx , parser := range t .parserOrder [stage ] {
215203 res := parsers [parser ].Success
@@ -289,60 +277,83 @@ func (t *tree) displayResults(opts DumpOpts) {
289277 }
290278
291279 if res {
292- fmt .Printf ( "\t %s\t %s %s %s (%s)\n " , presep , sep , emoji .GreenCircle , parser , changeStr )
280+ fmt .Fprintf ( os . Stdout , "\t %s\t %s %s %s (%s)\n " , presep , sep , emoji .GreenCircle , parser , changeStr )
293281
294282 if opts .Details {
295- fmt .Print ( detailsDisplay )
283+ fmt .Fprint ( os . Stdout , detailsDisplay )
296284 }
297285 } else if opts .ShowNotOkParsers {
298- fmt .Printf ( "\t %s\t %s %s %s\n " , presep , sep , emoji .RedCircle , parser )
286+ fmt .Fprintf ( os . Stdout , "\t %s\t %s %s %s\n " , presep , sep , emoji .RedCircle , parser )
299287 }
300288 }
301289 }
302290
303- sep := "└"
291+ buckets := t .state [tstamp ]["buckets" ]
292+ displayBucketSection (buckets , whitelistReason )
293+ }
294+ }
304295
305- if len (t .state [tstamp ]["buckets" ]) > 0 {
306- sep = "├"
307- }
296+ func sortedStages (state map [string ]map [string ]ParserResult ) []string {
297+ ret := make ([]string , 0 , len (state ))
308298
309- // did the event enter the bucket pour phase ?
310- if _ , ok := t .state [tstamp ]["buckets" ]["OK" ]; ok {
311- fmt .Printf ("\t %s-------- parser success %s\n " , sep , emoji .GreenCircle )
312- } else if whitelistReason != "" {
313- fmt .Printf ("\t %s-------- parser success, ignored by whitelist (%s) %s\n " , sep , whitelistReason , emoji .GreenCircle )
314- } else {
315- fmt .Printf ("\t %s-------- parser failure %s\n " , sep , emoji .RedCircle )
316- }
299+ for k := range state {
300+ // there is a trick: to know if an event successfully exit the parsers, we check if it reached the pour() phase
301+ // we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
302+ if k == "buckets" {
303+ continue
304+ }
317305
318- // now print bucket info
319- if len (t .state [tstamp ]["buckets" ]) > 0 {
320- fmt .Print ("\t ├ Scenarios\n " )
321- }
306+ ret = append (ret , k )
307+ }
322308
323- bnames := make ([] string , 0 , len ( t . state [ tstamp ][ "buckets" ]) )
309+ sort . Strings ( ret )
324310
325- for k := range t .state [tstamp ]["buckets" ] {
326- // there is a trick : to know if an event successfully exit the parsers, we check if it reached the pour() phase
327- // we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
328- if k == "OK" {
329- continue
330- }
311+ return ret
312+ }
313+
314+ func displayBucketSection (buckets map [string ]ParserResult , whitelistReason string ) {
315+ sep := "└"
316+
317+ if len (buckets ) > 0 {
318+ sep = "├"
319+ }
320+
321+ // did the event enter the bucket pour phase ?
322+ if _ , ok := buckets ["OK" ]; ok {
323+ fmt .Fprintf (os .Stdout , "\t %s-------- parser success %s\n " , sep , emoji .GreenCircle )
324+ } else if whitelistReason != "" {
325+ fmt .Fprintf (os .Stdout , "\t %s-------- parser success, ignored by whitelist (%s) %s\n " , sep , whitelistReason , emoji .GreenCircle )
326+ } else {
327+ fmt .Fprintf (os .Stdout , "\t %s-------- parser failure %s\n " , sep , emoji .RedCircle )
328+ }
331329
332- bnames = append (bnames , k )
330+ // now print bucket info
331+ if len (buckets ) > 0 {
332+ fmt .Fprint (os .Stdout , "\t ├ Scenarios\n " )
333+ }
334+
335+ bnames := make ([]string , 0 , len (buckets ))
336+
337+ for k := range buckets {
338+ // there is a trick : to know if an event successfully exit the parsers, we check if it reached the pour() phase
339+ // we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
340+ if k == "OK" {
341+ continue
333342 }
334343
335- sort .Strings (bnames )
344+ bnames = append (bnames , k )
345+ }
336346
337- for idx , bname := range bnames {
338- sep := "├"
339- if idx == len (bnames )- 1 {
340- sep = "└"
341- }
347+ sort .Strings (bnames )
342348
343- fmt .Printf ("\t \t %s %s %s\n " , sep , emoji .GreenCircle , bname )
349+ for idx , bname := range bnames {
350+ sep := "├"
351+ if idx == len (bnames )- 1 {
352+ sep = "└"
344353 }
345354
346- fmt .Println ( )
355+ fmt .Fprintf ( os . Stdout , " \t \t %s %s %s \n " , sep , emoji . GreenCircle , bname )
347356 }
357+
358+ fmt .Fprintln (os .Stdout )
348359}
0 commit comments