@@ -279,7 +279,7 @@ func (r *runner) cat(filename string) (err error) {
279279 })
280280 }
281281
282- if len (r .pass ) > 0 || len (r .skip ) > 0 {
282+ if len (r .pass ) > 0 || len (r .skip ) > 0 || r . parallel > 1 {
283283 r .scanFile (rd , out )
284284 } else {
285285 r .readFile (rd , out )
@@ -364,6 +364,8 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo
364364 skip stringFlags
365365 )
366366
367+ r := & runner {}
368+
367369 flag .Var (& pass , "pass" , "filter matching, may contain multiple AND patterns separated by ^,\n " +
368370 "if filter matches, line is passed to the output (unless filtered out by -skip)\n " +
369371 "each -pass value is added with OR logic,\n " +
@@ -374,20 +376,21 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo
374376 "each -skip value is added with OR logic,\n " +
375377 "for example, you can use \" -skip quux^baz -skip fooO\" to skip lines that have (quux AND baz) OR fooO" )
376378
377- parallel := flag .Int ( "parallel" , 1 , "number of parallel readers if multiple files are provided\n " +
379+ flag .IntVar ( & r . parallel , "parallel" , 1 , "number of parallel readers if multiple files are provided\n " +
378380 "lines from different files will go to output simultaneously (out of order of files, but in order of lines in each file)\n " +
379381 "use 0 for multi-threaded zst decoder (slightly faster at cost of more CPU)" )
380382
381383 cpuProfile := flag .String ("dbg-cpu-prof" , "" , "write first 10 seconds of CPU profile to file" )
382384 memProfile := flag .String ("dbg-mem-prof" , "" , "write heap profile to file after 10 seconds" )
383385 output := flag .String ("output" , "" , "output to file instead of STDOUT" )
384- outDir := flag .String ("out-dir" , "" , "output to directory instead of STDOUT\n " +
385- "files will be written to out dir with original base names\n " +
386- "disables output flag" )
387386 noProgress := flag .Bool ("no-progress" , false , "disable progress printing" )
388387 progressJSON := flag .String ("progress-json" , "" , "write current progress to a file" )
389388 ver := flag .Bool ("version" , false , "print version and exit" )
390389
390+ flag .StringVar (& r .outDir , "out-dir" , "" , "output to directory instead of STDOUT\n " +
391+ "files will be written to out dir with original base names\n " +
392+ "disables output flag" )
393+
391394 flag .Usage = func () {
392395 fmt .Println ("catp" , version .Module ("github.com/bool64/progress" ).Version + "," ,
393396 version .Info ().GoVersion , strings .Join (versionExtra , " " ))
@@ -420,12 +423,7 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo
420423 defer pprof .StopCPUProfile ()
421424 }
422425
423- r := & runner {}
424-
425- r .parallel = * parallel
426- r .outDir = * outDir
427-
428- if * output != "" && * outDir == "" { //nolint:nestif
426+ if * output != "" && r .outDir == "" { //nolint:nestif
429427 out , err := os .Create (* output )
430428 if err != nil {
431429 return fmt .Errorf ("failed to create output file %s: %w" , * output , err )
@@ -503,7 +501,7 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo
503501 r .sizes [fn ] = st .Size ()
504502 }
505503
506- if * parallel >= 2 {
504+ if r . parallel >= 2 {
507505 pr := r .pr
508506 pr .Start (func (t * progress.Task ) {
509507 t .TotalBytes = func () int64 { return r .totalBytes }
@@ -513,7 +511,7 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo
513511 t .PrintOnStart = true
514512 })
515513
516- sem := make (chan struct {}, * parallel )
514+ sem := make (chan struct {}, r . parallel )
517515 errs := make (chan error , 1 )
518516
519517 for i := 0 ; i < flag .NArg (); i ++ {
0 commit comments