aboutsummaryrefslogtreecommitdiff
path: root/internal/plan
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 22:12:31 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 22:12:31 +0200
commit88cbe4e623eab9adb608566ac636d36eed72e551 (patch)
treea55e50b49ded3f386772cecc4f8ab1e71613014d /internal/plan
parent77a015b96db8727bb12d0869f180a44d087f6319 (diff)
downloadkrino-88cbe4e623eab9adb608566ac636d36eed72e551.tar.gz
krino-88cbe4e623eab9adb608566ac636d36eed72e551.zip
check refuses placeholders that could never expand
Diffstat (limited to 'internal/plan')
-rw-r--r--internal/plan/index.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/plan/index.go b/internal/plan/index.go
index abe073f..0409295 100644
--- a/internal/plan/index.go
+++ b/internal/plan/index.go
@@ -6,8 +6,22 @@ import (
"fmt"
"strconv"
"strings"
+ "time"
)
+// CheckTemplate reports the first reason s's placeholders could never
+// expand - an unknown placeholder, {mtime} or {now} without a format, an
+// unknown format code, {0}, {10} and up, an unclosed "{" - or nil. Capture
+// counts are not checked here; that needs the rule's name tests.
+func CheckTemplate(s string) error {
+ if _, err := MaxIndex(s); err != nil {
+ return err
+ }
+ facts := Facts{Name: "a.b", Captures: make([]string, 10), ModTime: time.Unix(0, 0), Now: time.Unix(0, 0)}
+ _, err := Expand(s, facts)
+ return err
+}
+
// MaxIndex returns the highest {N} used in s, 0 when none. It reports the
// same errors Expand does for a malformed placeholder: an unclosed
// placeholder, or {0} (capture groups are numbered from 1). It shares