Fix REPL output for multiple bool exprs

The presentation implementation was trying to print a table with no
expression values or variable bindings. With these changes, the
presentation package will output 'true' if there are no vars and all of
the exprs are of type 'bool'.

Fixes #850

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2018-07-26 11:03:35 -07:00
parent f59aade0f8
commit aaf2ee0323
+11 -2
View File
@@ -116,8 +116,8 @@ func prettyResult(w io.Writer, rs rego.ResultSet, limit int) error {
return nil
}
if len(rs) == 1 {
if len(rs[0].Bindings) == 0 && len(rs[0].Expressions) == 1 {
if len(rs) == 1 && len(rs[0].Bindings) == 0 {
if len(rs[0].Expressions) == 1 || allBoolean(rs[0].Expressions) {
return JSON(w, rs[0].Expressions[0].Value)
}
}
@@ -313,3 +313,12 @@ func generateResultKeys(rs rego.ResultSet) []resultKey {
}
return keys
}
func allBoolean(ev []*rego.ExpressionValue) bool {
for i := range ev {
if _, ok := ev[i].Value.(bool); !ok {
return false
}
}
return true
}