feat: require explicit @param required flag and improve run failure output with params details

This commit is contained in:
2026-02-24 23:55:31 +08:00
parent fb6ffc1d4f
commit 07d5c1db52
4 changed files with 146 additions and 10 deletions

View File

@@ -225,10 +225,31 @@ fun colorizeStatusLine(line: String): String =
fun prettyPrintJsonOrKeep(raw: String): String {
val text = raw.trim()
if (!(text.startsWith("{") || text.startsWith("["))) return raw
if (!isLikelyJson(text)) return raw
return runCatching { prettyJson(text) }.getOrElse { raw }
}
fun isLikelyJson(text: String): Boolean {
if (text.isBlank()) return false
val first = text.first()
if (first != '{' && first != '[') return false
val second = text.drop(1).firstOrNull { !it.isWhitespace() } ?: return false
return when (first) {
'{' -> second == '"' || second == '}'
'[' -> second == ']' ||
second == '{' ||
second == '[' ||
second == '"' ||
second == '-' ||
second.isDigit() ||
second == 't' ||
second == 'f' ||
second == 'n'
else -> false
}
}
fun prettyJson(input: String): String {
val sb = StringBuilder(input.length + 32)
var indent = 0
@@ -455,7 +476,7 @@ fun initialScriptTemplate(name: String): String =
"""
// @desc: $name
// @timeout: 10s
// @param: sample | default=value | desc=example parameter
// @param: sample | required=false | default=value | desc=example parameter
val args: Array<String> = emptyArray()
val kv = args.mapNotNull {