1
1
package main
2
2
3
3
import (
4
+ "bufio"
4
5
"fmt"
6
+ "io"
5
7
"os"
6
8
"path/filepath"
7
9
"strings"
@@ -49,10 +51,13 @@ func main() {
49
51
ownerFilters [i ] = strings .TrimLeft (ownerFilters [i ], "@" )
50
52
}
51
53
54
+ out := bufio .NewWriter (os .Stdout )
55
+ defer out .Flush ()
56
+
52
57
for _ , startPath := range paths {
53
58
// godirwalk only accepts directories, so we need to handle files separately
54
59
if ! isDir (startPath ) {
55
- if err := printFileOwners (ruleset , startPath , ownerFilters , showUnowned ); err != nil {
60
+ if err := printFileOwners (out , ruleset , startPath , ownerFilters , showUnowned ); err != nil {
56
61
fmt .Fprintf (os .Stderr , "error: %v" , err )
57
62
os .Exit (1 )
58
63
}
@@ -66,7 +71,7 @@ func main() {
66
71
67
72
// Only show code owners for files, not directories
68
73
if ! d .IsDir () {
69
- return printFileOwners (ruleset , path , ownerFilters , showUnowned )
74
+ return printFileOwners (out , ruleset , path , ownerFilters , showUnowned )
70
75
}
71
76
return nil
72
77
})
@@ -78,7 +83,7 @@ func main() {
78
83
}
79
84
}
80
85
81
- func printFileOwners (ruleset codeowners.Ruleset , path string , ownerFilters []string , showUnowned bool ) error {
86
+ func printFileOwners (out io. Writer , ruleset codeowners.Ruleset , path string , ownerFilters []string , showUnowned bool ) error {
82
87
rule , err := ruleset .Match (path )
83
88
if err != nil {
84
89
return err
@@ -87,7 +92,7 @@ func printFileOwners(ruleset codeowners.Ruleset, path string, ownerFilters []str
87
92
if rule == nil || rule .Owners == nil {
88
93
// Unless explicitly requested, don't show unowned files if we're filtering by owner
89
94
if len (ownerFilters ) == 0 || showUnowned {
90
- fmt .Printf ( "%-70s (unowned)\n " , path )
95
+ fmt .Fprintf ( out , "%-70s (unowned)\n " , path )
91
96
}
92
97
return nil
93
98
}
@@ -109,7 +114,7 @@ func printFileOwners(ruleset codeowners.Ruleset, path string, ownerFilters []str
109
114
110
115
// If the owners slice is empty, no owners matched the filters so don't show anything
111
116
if len (owners ) > 0 {
112
- fmt .Printf ( "%-70s %s\n " , path , strings .Join (owners , " " ))
117
+ fmt .Fprintf ( out , "%-70s %s\n " , path , strings .Join (ownersToShow , " " ))
113
118
}
114
119
return nil
115
120
}
0 commit comments