Implement TextEncoder for better readability
bcho opened this issue · 1 comments
bcho commented
When using sg
from local, we should provide a TextEncoder
for better readability. Similar to the JSON
encoder, we can implement like this:
// sg/internal/result/presenter/text.go
func Text(queryResultsList []result.QueryResults) WriteQueryResultTo {
return writeQueryResultToFunc(func(w io.Writer) error {
for _, queryResult := range queryResultsList { // TODO: maybe we should sort & group results before iterating them
fmt.Fprintf(w, "%s - %s - %s", <kind>, <file-path>, <message>)
}
})
}
conftest is providing similar output like this:
$ conftest test -p ./sg/internal/cli/test/testdata/bug25/policy ./sg/internal/cli/test/testdata/bug25/configurations/data.json
WARN - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
FAIL - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
FAIL - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
bcho commented
conftest's implementation for reference: https://github.com/open-policy-agent/conftest/blob/55834493ce76e76241479ede4e3c711010a7bf5c/output/standard.go#L63-L96