execline-json/json-defines

36 lines
874 B
Text
Raw Normal View History

2022-08-05 20:47:29 +00:00
#!/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"
}
}