-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement conditional constants #1373
Conversation
8bb77b9
to
e0fc588
Compare
9020ed9
to
850e589
Compare
Signed-off-by: Pablo Herrera <[email protected]>
850e589
to
ec27914
Compare
Signed-off-by: Pablo Herrera <[email protected]>
ec27914
to
b55573e
Compare
While i think this may not have gotten enough testing, basic testing was done and if bugs surface we can fix them at a later time. The testing in this case doesn't need to hold back the impl being more widely available. |
The The following will always use <constants fallback="true">
<constant id="const">Fallback</constant>
</constants> However the below works with <constants>
<constant id="const" fallback="true">Fallback</constant>
</constants> Is this intentional? As the example provided is different to the actual behaviour. |
not intentional, will take a look and fix it |
Implements section 3.2.1 in #1181, in the second bulletpoint way, where constants are processed at the same time as includes. This means that constants can be used in conditionals (
<if> / <unless>
), but only if defined before the conditional.TLDR;
fallback
attribute, defaults to false. If true, the constant is a fallback (a default) and will NOT override a prior declaration.<constants>
tag and it applies to all children<if>
and<unless>
) can now work on constants, as long as they were defined before the conditional.min-server-version
andmax-server-version
attributes to conditionalsExamples
the-include.xml:
Map A.xml:
Map B:
Map C:
This is the most basic usage of the constant in a conditional, this defaults to if anyone has set a value for the constant or not.
<filter> </filter>
when time is deleted.IMPORTANT: constants in conditionals only work if declared BEFORE the conditional is evaluated, and CAN be different values.
Constant fallback attribute
Because of this behavior where defining the constant BEFORE the include is needed, but you likely want your definition to prevail over the includes', it makes sense for all includes to declare their constants as fallback:
Now these constants can be overwritten before the include (so that they work on conditionals too) without the include imposing them. So all maps using the include by default use 5m, and maps who want to disable it can just set it to delete="true". Note that
fallback
can be specified either on theconstant
or theconstants
parents, similar to many other features in PGM.All conditional constant options
Now, can you check more than just the conditional being set? the answer is yes, but it gets a bit complicated:
Attributes:
constant
: (required) the id of the constant to check againstconstant-value
: (depends on compare) the value to check for, this depends on the type of comparison doneconstant-comparison
: (optional) the type of comparison, like just checking if it is defined, or checking if it matches specific values. If not set, defaults todefined_value
if no value, orequals
if there's a value.(Note: the default changed from
defined
todefined_value
in #1381, this comment was updated to reflect it)All possible constant-comparison possibilities (case-insensitive):
<if constant="const" constant-comparison="undefined"/>
<if constant="const" constant-comparison="defined"/>
<if constant="const" constant-comparison="defined delete"/>
<if constant="const" constant-comparison="defined value"/>
constant-value
attribute is not definedconstant-value
<if constant="const" constant-value="5m" />
constant-value
is definedconstant-value
<if constant="const" constant-value="a,b,c" constant-comparison="contains"/>
<if constant="const" constant-value="[0-9]+" constant-comparison="regex"/>
<if constant="const" constant-value="0..12" constant-comparison="range"/>
const
is a number between 0 and 12Last notes
I hope this is enough to understand all the possibilities here, good luck to the documenters.