@@ -5,12 +5,14 @@ import (
55 "bufio"
66 "bytes"
77 "encoding/json"
8+ "errors"
89 "flag"
910 "fmt"
1011 "io"
1112 "log"
1213 "os"
1314 "path"
15+ "path/filepath"
1416 "runtime/pprof"
1517 "strings"
1618 "sync"
@@ -551,7 +553,8 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
551553 r .sizes = make (map [string ]int64 )
552554 r .progressJSON = * progressJSON
553555 r .pr = & progress.Progress {
554- Interval : 5 * time .Second ,
556+ Interval : 5 * time .Second ,
557+ IncrementalSpeed : true ,
555558 Print : func (status progress.Status ) {
556559 s := r .st (status )
557560
@@ -563,9 +566,32 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
563566 },
564567 }
565568
566- for i := 0 ; i < flag .NArg (); i ++ {
567- fn := flag .Arg (i )
569+ var files []string
568570
571+ for _ , f := range flag .Args () {
572+ glob , err := filepath .Glob (f )
573+ if err != nil {
574+ return err
575+ }
576+
577+ for _ , f := range glob {
578+ alreadyThere := false
579+
580+ for _ , e := range files {
581+ if e == f {
582+ alreadyThere = true
583+
584+ break
585+ }
586+ }
587+
588+ if ! alreadyThere {
589+ files = append (files , f )
590+ }
591+ }
592+ }
593+
594+ for _ , fn := range files {
569595 st , err := os .Stat (fn )
570596 if err != nil {
571597 return fmt .Errorf ("failed to read file stats %s: %w" , fn , err )
@@ -586,10 +612,11 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
586612 })
587613
588614 sem := make (chan struct {}, r .parallel )
589- errs := make (chan error , 1 )
615+ errs := make (chan error , r .parallel )
616+
617+ for _ , fn := range files {
618+ fn := fn
590619
591- for i := 0 ; i < flag .NArg (); i ++ {
592- i := i
593620 select {
594621 case err := <- errs :
595622 return err
@@ -601,8 +628,8 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
601628 <- sem
602629 }()
603630
604- if err := r .cat (flag . Arg ( i ) ); err != nil {
605- errs <- err
631+ if err := r .cat (fn ); err != nil {
632+ errs <- fmt . Errorf ( "%s: %w" , fn , err )
606633 }
607634 }()
608635 }
@@ -616,13 +643,21 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo,maintidx
616643
617644 close (errs )
618645
619- if err := <- errs ; err != nil {
620- return err
646+ var errValues []error
647+
648+ for err := range errs {
649+ if err != nil {
650+ errValues = append (errValues , err )
651+ }
652+ }
653+
654+ if errValues != nil {
655+ return errors .Join (errValues ... )
621656 }
622657 } else {
623- for i := 0 ; i < flag . NArg (); i ++ {
624- if err := r .cat (flag . Arg ( i ) ); err != nil {
625- return err
658+ for _ , fn := range files {
659+ if err := r .cat (fn ); err != nil {
660+ return fmt . Errorf ( "%s: %w" , fn , err )
626661 }
627662 }
628663 }
0 commit comments