Closed mjpieters closed 1 week ago
There are a few changes in behavior:
using undefined variables in an expression now provides a much friendlier error:
$ tbls --when 'foo'
unknown name foo (1:1)
| foo
| ^
Before you got:
$ tbls --when 'foo'
cannot fetch foo from struct { Env map[string]string } (1:2)
| (foo) == true
| .^
You now also get an error when the expression isn't going to produce a boolean value:
$ tbls --when '$SHELL'
expected bool, but got string
Without this PR, there was no error, the test simply failed because no string is ever equal to true.
Accessing an environment variable that doesn't exist results in an empty string (the default 'zero' value for the string type):
$ tbls --when '$NONESUCH != ""'
where before this would be a (cryptic) error:
$ tbls --when '$NONESUCH != ""'
cannot fetch $NONESUCH from struct { Env map[string]string } (1:2)
| ($NONESUCH != "") == true
| .^
You can use in
and not in
to test if a variable is defined, instead:
$ tbls --when '"NONESUCH" in Env`
@mjpieters Looks Great!!! thank you!!!
$
with aEnv.
member lookup.expr.AsBool()
to assert the expression produces a booleanFixes #599