Open trulede opened 1 month ago
Seems like the the code is only checking if the variable exists, not if it is also set.
Expectation is that nil or "" (empty string) would cause such a variable to fail the requires checks.
Seems like the the code is only checking if the variable exists, not if it is also set.
Expectation is that nil or "" (empty string) would cause such a variable to fail the requires checks.
Documentation has this:
Variables set to empty zero length strings, will pass the requires check.
which is not so good. I really have to question that, both in what it means (what is an empty and zero length string), and if such behavior is even useful. The code behind variables is quite involved, so in many places you find variables being defaulted to an empty string (i.e. ""
) and other things.
Again with the documentation:
If you want to check that certain variables are set before running a task then you can use requires. This is useful when might not be clear to users which variables are needed, or if you want clear message about what is required. Also some tasks could have dangerous side effects if run with un-set variables.
which seems OK, but misses the use-cases where one task calls another with non-trivial variable passing, and included task files ... these are cases where requires
would be useful. We have it in our task files, but it only acts as documentation for us (since it does not work).
I think the required checks should be:
In the case that 3 would not be accepted as part of the implementation, then we need a way to set a variable to nil
via the template engine (e.g a slim sprig function).
Discussed in https://github.com/go-task/task/discussions/1620