execline-json/json-defines
2022-08-05 22:49:59 +02:00

36 lines
874 B
Plaintext
Executable file

#!/bin/execlineb
multisubstitute {
importas -ui name 1
importas -ui input 2
}
foreground {
s6-echo "define
${name}
${input}"
}
case "$input" {
"\\{.*\\}" {
pipeline { s6-unquote -d "{}" "$input" }
pipeline { json-split-entries }
forstdin -E entry
backtick -E quoted_key { pipeline { s6-echo "${entry}" } cut -d ":" -f1 }
backtick -E value { pipeline { s6-echo $entry } cut -d ":" -f2- }
backtick -E key { s6-unquote "$quoted_key" }
json-defines "${name}[${key}]" "$value"
}
"\\[.*\\]" {
pipeline { s6-unquote -d "[]" $input }
pipeline { json-split-entries }
pipeline { s6-grep -n . }
forstdin -E entry
backtick -E lua_index { pipeline { s6-echo $entry } cut -d ":" -f1 }
backtick -I -E index { s6-expr "$lua_index" - 1 }
backtick -E value { pipeline { s6-echo $entry } cut -d ":" -f2- }
json-defines "${name}[${index}]" "$value"
}
}