Let a declared datatype win over a column read, count a repeat as written, refuse null alone on stdin and a second leading slash, and hand NewTemplate stdin as sent

This commit is contained in:
2026-10-07 22:55:09 +02:00
committed by Lillem4n
parent 1a022dbd79
commit 6b26b18104
12 changed files with 73 additions and 118 deletions
+14 -3
View File
@@ -16,12 +16,23 @@ func IsTemplate(arg string) (bool, error) {
if strings.HasPrefix(strings.TrimSpace(arg), "[") {
return false, fmt.Errorf(`%q starts with "[" and is not valid JSON, so it names no template; a path starts with a name`, arg)
}
_, err := SplitPath(CallerPath(arg))
path, err := CallerPath(arg)
if err != nil {
return false, err
}
_, err = SplitPath(path)
return false, err
}
// CallerPath is a path as a caller passed it, without the slashes it may start with.
func CallerPath(path string) string { return strings.TrimLeft(path, "/") }
// CallerPath is a path as a caller passed it, without the one / it may start with, as a
// reference does.
func CallerPath(path string) (string, error) {
rest := strings.TrimPrefix(path, "/")
if strings.HasPrefix(rest, "/") {
return "", fmt.Errorf("path %s starts with more than one /; write /%s", path, strings.TrimLeft(rest, "/"))
}
return rest, nil
}
func isJSONStart(arg string) bool {
return strings.HasPrefix(arg, "[") || strings.HasPrefix(arg, `"`)