Skip to content

Commit

Permalink
Fixing code quality on GoReportCard
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSec committed Jun 24, 2020
1 parent fe2c451 commit 406a8ba
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 725 deletions.
108 changes: 54 additions & 54 deletions app/list.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
package app

import (
"io/ioutil"
"log"
"os"

"github.com/jedib0t/go-pretty/table"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

// List checks of config file
func List(cmd *cobra.Command, args []string) {

configFile, _ := cmd.Flags().GetString("config-file")
severity, _ := cmd.Flags().GetString("severity")

file, err := os.Open(configFile)
if err != nil {
log.Fatal(err)
}

defer file.Close()
data, err := ioutil.ReadAll(file)
y := Config{}

err = yaml.Unmarshal([]byte(data), &y)
if err != nil {
log.Fatalf("error: %v", err)
}
cpt := 0
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"URL", "Plugin Name", "Severity", "Description"})
for index, plugin := range y.Plugins {
_ = index
for index, check := range plugin.Checks {
_ = index
// If the user wants a specific severity, collect only specified severity checks
if severity != "" {
if severity == string(*check.Severity) {
t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description})
cpt++
}
} else {
t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description})
cpt++
}
}
}
t.AppendFooter(table.Row{"", "", "Total Checks", cpt})
t.Render()
}
package app

import (
"io/ioutil"
"log"
"os"

"github.com/jedib0t/go-pretty/table"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

// List checks of config file
func List(cmd *cobra.Command, args []string) {

configFile, _ := cmd.Flags().GetString("config-file")
severity, _ := cmd.Flags().GetString("severity")

file, err := os.Open(configFile)
if err != nil {
log.Fatal(err)
}

defer file.Close()
data, err := ioutil.ReadAll(file)
y := Config{}

err = yaml.Unmarshal([]byte(data), &y)
if err != nil {
log.Fatalf("error: %v", err)
}
cpt := 0
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"URL", "Plugin Name", "Severity", "Description"})
for index, plugin := range y.Plugins {
_ = index
for index, check := range plugin.Checks {
_ = index
// If the user wants a specific severity, collect only specified severity checks
if severity != "" {
if severity == string(*check.Severity) {
t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description})
cpt++
}
} else {
t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description})
cpt++
}
}
}
t.AppendFooter(table.Row{"", "", "Total Checks", cpt})
t.Render()
}
Loading

0 comments on commit 406a8ba

Please sign in to comment.