|
1 |
| -package app |
2 |
| - |
3 |
| -import ( |
4 |
| - "io/ioutil" |
5 |
| - "log" |
6 |
| - "os" |
7 |
| - |
8 |
| - "github.com/jedib0t/go-pretty/table" |
9 |
| - "github.com/spf13/cobra" |
10 |
| - "gopkg.in/yaml.v2" |
11 |
| -) |
12 |
| - |
13 |
| -// List checks of config file |
14 |
| -func List(cmd *cobra.Command, args []string) { |
15 |
| - |
16 |
| - configFile, _ := cmd.Flags().GetString("config-file") |
17 |
| - severity, _ := cmd.Flags().GetString("severity") |
18 |
| - |
19 |
| - file, err := os.Open(configFile) |
20 |
| - if err != nil { |
21 |
| - log.Fatal(err) |
22 |
| - } |
23 |
| - |
24 |
| - defer file.Close() |
25 |
| - data, err := ioutil.ReadAll(file) |
26 |
| - y := Config{} |
27 |
| - |
28 |
| - err = yaml.Unmarshal([]byte(data), &y) |
29 |
| - if err != nil { |
30 |
| - log.Fatalf("error: %v", err) |
31 |
| - } |
32 |
| - cpt := 0 |
33 |
| - t := table.NewWriter() |
34 |
| - t.SetOutputMirror(os.Stdout) |
35 |
| - t.AppendHeader(table.Row{"URL", "Plugin Name", "Severity", "Description"}) |
36 |
| - for index, plugin := range y.Plugins { |
37 |
| - _ = index |
38 |
| - for index, check := range plugin.Checks { |
39 |
| - _ = index |
40 |
| - // If the user wants a specific severity, collect only specified severity checks |
41 |
| - if severity != "" { |
42 |
| - if severity == string(*check.Severity) { |
43 |
| - t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description}) |
44 |
| - cpt++ |
45 |
| - } |
46 |
| - } else { |
47 |
| - t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description}) |
48 |
| - cpt++ |
49 |
| - } |
50 |
| - } |
51 |
| - } |
52 |
| - t.AppendFooter(table.Row{"", "", "Total Checks", cpt}) |
53 |
| - t.Render() |
54 |
| -} |
| 1 | +package app |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "log" |
| 6 | + "os" |
| 7 | + |
| 8 | + "github.com/jedib0t/go-pretty/table" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "gopkg.in/yaml.v2" |
| 11 | +) |
| 12 | + |
| 13 | +// List checks of config file |
| 14 | +func List(cmd *cobra.Command, args []string) { |
| 15 | + |
| 16 | + configFile, _ := cmd.Flags().GetString("config-file") |
| 17 | + severity, _ := cmd.Flags().GetString("severity") |
| 18 | + |
| 19 | + file, err := os.Open(configFile) |
| 20 | + if err != nil { |
| 21 | + log.Fatal(err) |
| 22 | + } |
| 23 | + |
| 24 | + defer file.Close() |
| 25 | + data, err := ioutil.ReadAll(file) |
| 26 | + y := Config{} |
| 27 | + |
| 28 | + err = yaml.Unmarshal([]byte(data), &y) |
| 29 | + if err != nil { |
| 30 | + log.Fatalf("error: %v", err) |
| 31 | + } |
| 32 | + cpt := 0 |
| 33 | + t := table.NewWriter() |
| 34 | + t.SetOutputMirror(os.Stdout) |
| 35 | + t.AppendHeader(table.Row{"URL", "Plugin Name", "Severity", "Description"}) |
| 36 | + for index, plugin := range y.Plugins { |
| 37 | + _ = index |
| 38 | + for index, check := range plugin.Checks { |
| 39 | + _ = index |
| 40 | + // If the user wants a specific severity, collect only specified severity checks |
| 41 | + if severity != "" { |
| 42 | + if severity == string(*check.Severity) { |
| 43 | + t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description}) |
| 44 | + cpt++ |
| 45 | + } |
| 46 | + } else { |
| 47 | + t.AppendRow([]interface{}{plugin.URI, check.PluginName, *check.Severity, *check.Description}) |
| 48 | + cpt++ |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + t.AppendFooter(table.Row{"", "", "Total Checks", cpt}) |
| 53 | + t.Render() |
| 54 | +} |
0 commit comments