Skip to content

Commit 33b228d

Browse files
authored
Merge pull request #210 from vmarkovtsev/master
Add --only to combine cmd
2 parents 5b6ccf7 + 145649a commit 33b228d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

cmd/hercules/combine.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ var combineCmd = &cobra.Command{
3131
panic(err)
3232
}
3333
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+
}
3538
return
3639
}
40+
only, err := cmd.Flags().GetString("only")
41+
if err != nil {
42+
panic(err)
43+
}
3744
var repos []string
3845
allErrors := map[string][]string{}
3946
mergedResults := map[string]interface{}{}
@@ -52,7 +59,7 @@ var combineCmd = &cobra.Command{
5259
bar.Increment()
5360
anotherResults, anotherMetadata, errs := loadMessage(fileName, &repos)
5461
if anotherMetadata != nil {
55-
mergeResults(mergedResults, mergedMetadata, anotherResults, anotherMetadata)
62+
mergeResults(mergedResults, mergedMetadata, anotherResults, anotherMetadata, only)
5663
}
5764
allErrors[fileName] = errs
5865
debug.FreeOSMemory()
@@ -165,8 +172,12 @@ func printErrors(allErrors map[string][]string) {
165172
func mergeResults(mergedResults map[string]interface{},
166173
mergedCommons *hercules.CommonAnalysisResult,
167174
anotherResults map[string]interface{},
168-
anotherCommons *hercules.CommonAnalysisResult) {
175+
anotherCommons *hercules.CommonAnalysisResult,
176+
only string) {
169177
for key, val := range anotherResults {
178+
if only != "" && key != only {
179+
continue
180+
}
170181
mergedResult, exists := mergedResults[key]
171182
if !exists {
172183
mergedResults[key] = val
@@ -183,7 +194,17 @@ func mergeResults(mergedResults map[string]interface{},
183194
}
184195
}
185196

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+
186205
func init() {
187206
rootCmd.AddCommand(combineCmd)
188207
combineCmd.SetUsageFunc(combineCmd.UsageFunc())
208+
combineCmd.Flags().String("only", "", "Consider only the specified analysis. "+
209+
"Empty means all available. Choices: "+getOptionsString()+".")
189210
}

0 commit comments

Comments
 (0)