Class NaruAssertDirective
java.lang.Object
net.thevpc.naru.api.registry.NaruDirectiveBase
net.thevpc.naru.impl.registry.builtindirectives.NaruAssertDirective
- All Implemented Interfaces:
NaruDirective
Asserts a script condition in ONE line (it replaces the common
"/if cond /print ... /set var = 0 /else /print ... /end" pattern):
/assert lastExitCode == 0 /assert --set green calc42 == "42" /assert --fail fileCount == 3 (abort the script when false)The condition is evaluated exactly like an /if condition; the {{var}} interpolation of directive arguments already resolved values, so the log shows the actual numbers/strings being compared. A success publishes
lastExitCode=0 and logs "✓ assert <condition>"; a failure
publishes lastExitCode=1 and logs "✗ assert <condition>".
--set <var> AND-accumulates the outcome into the task env var
<var>: an unset var behaves as "true", a single failure flips it to
0 and later successes cannot raise it again. A chain of asserts can thus
drive ONE "everything green" flag, e.g. the /while exit condition of a
build loop.
--fail additionally aborts the script (task error) on the first
failure, for anyone who expects the classic "assert breaks out" semantics.
Without it /assert is non-fatal by design: a script may want to keep going
and only report the outcome.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.thevpc.naru.api.registry.NaruDirectiveBase
NaruDirectiveBase.AbstractSubCommand, NaruDirectiveBase.SubCommand, NaruDirectiveBase.SubCommandHelp -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class net.thevpc.naru.api.registry.NaruDirectiveBase
addCandidates, execute, executeHelp, getAliases, getDescription, group, name, noCommand, noCommand, register, resolveCandidates, subCommand
-
Constructor Details
-
NaruAssertDirective
public NaruAssertDirective()
-