1
0
mirror of https://github.com/strongdm/comply synced 2024-11-17 05:14:55 +00:00
comply/internal/cli/todo.go

69 lines
1.3 KiB
Go
Raw Normal View History

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",
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)
w.SetHeader([]string{"Framework", "Criterion", "Satisfied?", "Name"})
2018-05-15 21:13:11 +00:00
type row struct {
framework string
criterionKey string
2018-05-15 21:13:11 +00:00
satisfied string
criterionName string
2018-05-15 21:13:11 +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 {
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{
framework: std.Name,
criterionKey: id,
2018-05-15 21:13:11 +00:00
satisfied: sat,
criterionName: c.Name,
2018-05-15 21:13:11 +00:00
})
}
}
sort.Slice(rows, func(i, j int) bool {
return rows[i].criterionKey < rows[j].criterionKey
2018-05-15 21:13:11 +00:00
})
w.SetAutoWrapText(false)
for _, r := range rows {
w.Append([]string{r.framework, r.criterionKey, r.satisfied, r.criterionName})
2018-05-15 21:13:11 +00:00
}
w.Render()
return nil
}