beets
beets copied to clipboard
Variant of `%if` template function that does not treat 0 as false
As per the documentation:
%if{condition,text}or%if{condition,truetext,falsetext}: Ifconditionis nonempty (or nonzero, if it’s a number), then returns the second argument.
Is there a way this could be context dependent and act differently for different fields? I have an album simply titled "0", which failed the check %if{album,album/}. I've already rewritten my path format to avoid this issue, but it took me a while to realize what was wrong. Checking for 0 makes sense when you're checking numbers, but when you're checking strings I think it's more intuitive for 0 to evaluate to true.
Sorry if this has come up before, I tried searching but there's a lot to wade through searching for "if 0".
Argh, that's annoying! The use case makes sense... I don't think it's feasible to work differently for different fields (because %if isn't aware of the fields used to generate its arguments), but maybe a separate variant of %if would be good that is more strict about its "empty/nonempty" condition behavior.
I think the core issue is not that it's hard to work around this behavior, but rather that it's a little unintuitive so it's hard to expect/troubleshoot if you do run into a problem. A better solution might be to mention this in the documentation, maybe even with a proposed workaround.
Indeed; at least clarifying the docs would be ideal! I'm a bit worried about changing the behavior of %if because people could be relying on the current behavior, but documenting it and providing an alternative would be a good idea.