add defaults() fn. add --print-config. config loader now fails on error

This commit is contained in:
Patrick Stadler
2015-03-21 21:19:08 +01:00
parent e0a528859f
commit b518c807d1
16 changed files with 232 additions and 125 deletions

View File

@@ -48,8 +48,13 @@ parse_config () {
return
fi
#echo "${fn_name}_config () { ${_body}; }"
eval "${fn_name}_config () { ${_body}; }"
if ! eval "$_body" > /dev/null 2>&1; then
echo "Error parsing config section: $_name: $_body"
exit 1
fi
#echo "${fn_name}_config () { $_body; }"
eval "${fn_name}_config () { $_body; }"
}
for line in $(cat $1); do

View File

@@ -9,8 +9,6 @@ iso_date () {
}
in_array () {
local item=$1
local arr=$2
echo " $2 " | grep -q " $1 "
}
@@ -23,4 +21,8 @@ unique_id () {
LC_ALL=C
echo __u_$(cat /dev/urandom | tr -dc 'A-Za-z0-9' | head -c 10)
LC_ALL=$RESTORE_LC_ALL
}
print_prefixed () {
printf "$2" | sed -e "s/^/$1/g"
}

View File

@@ -6,9 +6,10 @@ load_reporter_with_prefix () {
local content
content=$(sed \
-e 's/^[[:space:]]*\(init[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(defaults[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(start[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(report[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(terminate[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(stop[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(docs[ ]*()[ ]*{\)/'"$prefix"'\1/' $file)
eval "$content"
@@ -21,9 +22,10 @@ load_metric_with_prefix () {
# dash will error if this variable is defined as `local`
content=$(sed \
-e 's/^[[:space:]]*\(init[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(defaults[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(start[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(collect[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(terminate[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(stop[ ]*()[ ]*{\)/'"$prefix"'\1/' \
-e 's/^[[:space:]]*\(docs[ ]*()[ ]*{\)/'"$prefix"'\1/' $file)
eval "$content"