mirror of
https://github.com/wimpysworld/stream-sprout
synced 2026-03-14 22:55:49 +01:00
fix(yaml): make parse_yaml() shellcheck compliant
This commit is contained in:
parent
67925af986
commit
a77c910db2
1 changed files with 12 additions and 7 deletions
|
|
@ -12,18 +12,23 @@ function ctrl_c() {
|
|||
|
||||
# https://stackoverflow.com/questions/5014632/how-can-i-parse-a-yaml-file-from-a-linux-shell-script
|
||||
function parse_yaml() {
|
||||
local prefix=$2
|
||||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
|
||||
sed -ne "s|^\($s\):|\1|" \
|
||||
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||
awk -F$fs '{
|
||||
local prefix="${2}"
|
||||
local s=""
|
||||
local w=""
|
||||
local fs=""
|
||||
s='[[:space:]]*'
|
||||
w='[a-zA-Z0-9_]*'
|
||||
fs=$(echo @|tr @ '\034')
|
||||
sed -ne "s|^\(${s}\):|\1|" \
|
||||
-e "s|^\(${s}\)\(${w}\)${s}:${s}[\"']\(.*\)[\"']$s\$|\1${fs}\2${fs}\3|p" \
|
||||
-e "s|^\(${s}\)\(${w}\)${s}:${s}\(.*\)${s}\$|\1${fs}\2${fs}\3|p" "${1}" |
|
||||
awk -F"${fs}" '{
|
||||
indent = length($1)/2;
|
||||
vname[indent] = $2;
|
||||
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||
if (length($3) > 0) {
|
||||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||
printf("%s%s%s=\"%s\"\n", "'"${prefix}"'",vn, $2, $3);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue