mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user