summaryrefslogtreecommitdiff
path: root/yadm
diff options
context:
space:
mode:
authorTim Byrne <sultan@locehilios.com>2019-10-05 11:01:13 -0500
committerTim Byrne <sultan@locehilios.com>2019-10-05 11:43:48 -0500
commit444622a658794a9090d9c8b792894a03b987c1b6 (patch)
treed6aaa023f70aa2315c126d44047acac87cd7c887 /yadm
parent81134c8edbf59df08f8d59d06058961aa112250f (diff)
Support `else` statements in builtin templates
Diffstat (limited to 'yadm')
-rwxr-xr-xyadm23
1 files changed, 16 insertions, 7 deletions
diff --git a/yadm b/yadm
index 2a9e989..e4df305 100755
--- a/yadm
+++ b/yadm
@@ -290,21 +290,30 @@ BEGIN {
c["hostname"] = host
c["user"] = user
c["distro"] = distro
- valid = conditions()
+ vld = conditions()
+ ifs = "^{%" blank "*if"
+ els = "^{%" blank "*else" blank "*%}$"
end = "^{%" blank "*endif" blank "*%}$"
- skip = "^{%" blank "*(if|endif)"
+ skp = "^{%" blank "*(if|else|endif)"
+ prt = 1
}
{ replace_vars() } # variable replacements
-$0 ~ valid, $0 ~ end { if ($0 ~ skip) next } # valid conditional blocks
-$0 ~ ("^{%" blank "*if"), $0 ~ end { next } # invalid conditional blocks
-{ print }
-
+$0 ~ vld, $0 ~ end {
+ if ($0 ~ vld || $0 ~ end) prt=1;
+ if ($0 ~ els) prt=0;
+ if ($0 ~ skp) next;
+}
+($0 ~ ifs && $0 !~ vld), $0 ~ end {
+ if ($0 ~ ifs && $0 !~ vld) prt=0;
+ if ($0 ~ els || $0 ~ end) prt=1;
+ if ($0 ~ skp) next;
+}
+{ if (prt) print }
function replace_vars() {
for (label in c) {
gsub(("{{" blank "*yadm\\." label blank "*}}"), c[label])
}
}
-
function conditions() {
pattern = "^{%" blank "*if" blank "*("
for (label in c) {