In a Justfile I'm building, I have use for "optional arguments". It would be helpful to have something like
target a *b:
echo {{ coalesce(b, a) }}
where the return value of coalesce is b is passed (i.e., its value has length > 0), and a otherwise. In that way, b would be an optional argument, with a as default.
Would a PR for this be welcome? The function name would probably need bike shedding, as SQL coalesce operates based on the first argument being NULL, not "empty".
It would (for my use case) be even nicer if there were syntax
target a *b=a:
echo {{ b }}
which currently fails with "error: Variable a not defined". Could this ever work? As the pieces seem there:
x := "abc"
target a *b=x:
echo {{ b }}
UDFs in general
Generally - for "user-defined functions" I'm currently using the following pattern
coalesce a *b:
@echo {{ a }}
target a *b:
echo $(just coalesce {{ b }} {{ a }})
Is this the intended way to have UDFs?
In a
JustfileI'm building, I have use for "optional arguments". It would be helpful to have something likewhere the return value of
coalesceisbis passed (i.e., its value has length > 0), andaotherwise. In that way,bwould be an optional argument, withaas default.Would a PR for this be welcome? The function name would probably need bike shedding, as SQL
coalesceoperates based on the first argument beingNULL, not "empty".It would (for my use case) be even nicer if there were syntax
which currently fails with "error: Variable
anot defined". Could this ever work? As the pieces seem there:UDFs in general
Generally - for "user-defined functions" I'm currently using the following pattern
Is this the intended way to have UDFs?