Skip to content

Commit

Permalink
fix: simplify getComponent and displayExceptions
Browse files Browse the repository at this point in the history
1. getComponent: since all users only use Component.Component, return it
   directly.

2. displayExceptions:
   - only use ToSlice once;
   - use %q and fmt.Println where appropriate.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 11, 2023
1 parent 2f335d6 commit 1196d62
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ var (
colTitleImage = "Image"
failureRowHeader = table.Row{colTitleOperatorName, colTitleTagName, colTitleExeName, colTitlePassedFailed, colTitleImage}
successRowHeader = table.Row{colTitleOperatorName, colTitleTagName, colTitleExeName, colTitleImage}
)

var (
colTitleNodePath = "Path"
colTitleNodePassedFailed = "Status"
colTitleNodeFrom = "From"
Expand Down Expand Up @@ -77,10 +75,10 @@ func displayExceptions(results []*ScanResults) {
continue
}
component := getComponent(res)
if set, ok := exceptions[component.Component]; ok {
if set, ok := exceptions[component]; ok {
set.Add(res)
} else {
exceptions[component.Component] = mapset.NewSet(res)
exceptions[component] = mapset.NewSet(res)
}
}
}
Expand All @@ -89,14 +87,15 @@ func displayExceptions(results []*ScanResults) {
if payloadName != "" {
fmt.Printf("[payload.%v]\n", payloadName)
}
if len(set.ToSlice()) == 1 {
fmt.Printf("filter_files = [ \"%v\" ]\n", set.ToSlice()[0].Path)
ss := set.ToSlice()
if len(ss) == 1 {
fmt.Printf("filter_files = [ %q ]\n", ss[0].Path)
} else {
fmt.Printf("filter_files = [\n")
for _, res := range set.ToSlice() {
fmt.Printf(" \"%v\",\n", res.Path)
fmt.Println("filter_files = [")
for _, res := range ss {
fmt.Printf(" %q,\n", res.Path)
}
fmt.Printf("]\n")
fmt.Println("]")
}
fmt.Println("")
}
Expand Down Expand Up @@ -162,13 +161,11 @@ func generateOutputString(cfg *Config, ftw table.Writer, stw table.Writer) (stri
return failureReport, successReport
}

func getComponent(res *ScanResult) *OpenshiftComponent {
func getComponent(res *ScanResult) string {
if res.Component != nil {
return res.Component
}
return &OpenshiftComponent{
Component: "<unknown>",
return res.Component.Component
}
return "<unknown>"
}

func renderReport(results []*ScanResults) (failures table.Writer, successes table.Writer) {
Expand All @@ -179,9 +176,9 @@ func renderReport(results []*ScanResults) (failures table.Writer, successes tabl
for _, res := range result.Items {
component := getComponent(res)
if res.Error != nil {
failureTableRows = append(failureTableRows, table.Row{component.Component, res.Tag.Name, res.Path, res.Error, res.Tag.From.Name})
failureTableRows = append(failureTableRows, table.Row{component, res.Tag.Name, res.Path, res.Error, res.Tag.From.Name})
} else {
successTableRows = append(successTableRows, table.Row{component.Component, res.Tag.Name, res.Path, res.Tag.From.Name})
successTableRows = append(successTableRows, table.Row{component, res.Tag.Name, res.Path, res.Tag.From.Name})
}
}
}
Expand Down

0 comments on commit 1196d62

Please sign in to comment.