2018-05-15 21:13:11 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
|
|
"github.com/strongdm/comply/internal/model"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var todoCommand = cli.Command{
|
|
|
|
Name: "todo",
|
2020-09-15 21:21:16 +00:00
|
|
|
Usage: "list declared vs satisfied compliance criteria",
|
2018-05-15 21:13:11 +00:00
|
|
|
Action: todoAction,
|
|
|
|
Before: projectMustExist,
|
|
|
|
}
|
|
|
|
|
|
|
|
func todoAction(c *cli.Context) error {
|
|
|
|
d, err := model.ReadData()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tablewriter.NewWriter(os.Stdout)
|
2020-09-15 21:21:16 +00:00
|
|
|
w.SetHeader([]string{"Framework", "Criterion", "Satisfied?", "Name"})
|
2018-05-15 21:13:11 +00:00
|
|
|
|
|
|
|
type row struct {
|
2020-09-15 21:21:16 +00:00
|
|
|
framework string
|
|
|
|
criterionKey string
|
2018-05-15 21:13:11 +00:00
|
|
|
satisfied string
|
2020-09-15 21:21:16 +00:00
|
|
|
criterionName string
|
2018-05-15 21:13:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 21:21:16 +00:00
|
|
|
satisfied := model.CriteriaSatisfied(d)
|
2018-05-15 21:13:11 +00:00
|
|
|
|
|
|
|
var rows []row
|
2020-09-15 19:52:22 +00:00
|
|
|
for _, std := range d.Frameworks {
|
2020-09-15 21:21:16 +00:00
|
|
|
for id, c := range std.Criteria{
|
2018-05-15 21:13:11 +00:00
|
|
|
sat := "NO"
|
|
|
|
if _, ok := satisfied[id]; ok {
|
|
|
|
sat = color.GreenString("YES")
|
|
|
|
}
|
|
|
|
|
|
|
|
rows = append(rows, row{
|
2020-09-15 21:21:16 +00:00
|
|
|
framework: std.Name,
|
|
|
|
criterionKey: id,
|
2018-05-15 21:13:11 +00:00
|
|
|
satisfied: sat,
|
2020-09-15 21:21:16 +00:00
|
|
|
criterionName: c.Name,
|
2018-05-15 21:13:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(rows, func(i, j int) bool {
|
2020-09-15 21:21:16 +00:00
|
|
|
return rows[i].criterionKey < rows[j].criterionKey
|
2018-05-15 21:13:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
w.SetAutoWrapText(false)
|
|
|
|
|
|
|
|
for _, r := range rows {
|
2020-09-15 21:21:16 +00:00
|
|
|
w.Append([]string{r.framework, r.criterionKey, r.satisfied, r.criterionName})
|
2018-05-15 21:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Render()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|