@@ -31,9 +31,16 @@ var combineCmd = &cobra.Command{
31
31
panic (err )
32
32
}
33
33
defer file .Close ()
34
- io .Copy (os .Stdout , bufio .NewReader (file ))
34
+ _ , err = io .Copy (os .Stdout , bufio .NewReader (file ))
35
+ if err != nil {
36
+ panic (err )
37
+ }
35
38
return
36
39
}
40
+ only , err := cmd .Flags ().GetString ("only" )
41
+ if err != nil {
42
+ panic (err )
43
+ }
37
44
var repos []string
38
45
allErrors := map [string ][]string {}
39
46
mergedResults := map [string ]interface {}{}
@@ -52,7 +59,7 @@ var combineCmd = &cobra.Command{
52
59
bar .Increment ()
53
60
anotherResults , anotherMetadata , errs := loadMessage (fileName , & repos )
54
61
if anotherMetadata != nil {
55
- mergeResults (mergedResults , mergedMetadata , anotherResults , anotherMetadata )
62
+ mergeResults (mergedResults , mergedMetadata , anotherResults , anotherMetadata , only )
56
63
}
57
64
allErrors [fileName ] = errs
58
65
debug .FreeOSMemory ()
@@ -165,8 +172,12 @@ func printErrors(allErrors map[string][]string) {
165
172
func mergeResults (mergedResults map [string ]interface {},
166
173
mergedCommons * hercules.CommonAnalysisResult ,
167
174
anotherResults map [string ]interface {},
168
- anotherCommons * hercules.CommonAnalysisResult ) {
175
+ anotherCommons * hercules.CommonAnalysisResult ,
176
+ only string ) {
169
177
for key , val := range anotherResults {
178
+ if only != "" && key != only {
179
+ continue
180
+ }
170
181
mergedResult , exists := mergedResults [key ]
171
182
if ! exists {
172
183
mergedResults [key ] = val
@@ -183,7 +194,17 @@ func mergeResults(mergedResults map[string]interface{},
183
194
}
184
195
}
185
196
197
+ func getOptionsString () string {
198
+ var leaves []string
199
+ for _ , leaf := range hercules .Registry .GetLeaves () {
200
+ leaves = append (leaves , leaf .Name ())
201
+ }
202
+ return strings .Join (leaves , ", " )
203
+ }
204
+
186
205
func init () {
187
206
rootCmd .AddCommand (combineCmd )
188
207
combineCmd .SetUsageFunc (combineCmd .UsageFunc ())
208
+ combineCmd .Flags ().String ("only" , "" , "Consider only the specified analysis. " +
209
+ "Empty means all available. Choices: " + getOptionsString ()+ "." )
189
210
}
0 commit comments