+mode=deploy
+manifest=
+verbose=0
+format=bash
+sourcefile=
+timestamp="$(date -u +%Y%m%d_%H%M%S_%Z)"
+
+function info() { echo "$@" >&2; }
+function error() { echo "$BASH_SOURCE: $@" >&2; }
+function out() { echo -n "$@"; }
+function out_object() {
+ # expected stdin stream is:
+ # --------------
+ # key
+ # value
+ # key
+ # value
+ # ...
+ # --------------
+ local sep=""
+ local k
+ case $format in
+ bash)
+ while read x; do
+ [[ -z "$k" ]] && { k="$x"; continue; }
+ out "$sep${k}="
+ out_value "$x"
+ sep=$'\n'
+ k=
+ done
+ out "$sep"
+ ;;
+ json)
+ out "{"
+ while read x; do
+ [[ -z "$k" ]] && { k="$x"; continue; }
+ out "$sep\"${k}\":"
+ out_value "$x"
+ sep=","
+ k=
+ done
+ out "}"
+ ;;
+ esac
+}
+
+function out_array() {
+ # expected stdin stream is:
+ # --------------
+ # value
+ # value
+ # ...
+ # --------------
+ local sep=""
+ case $format in
+ bash)
+ while read x; do
+ out "$sep"
+ out_value "$x"
+ sep=" "
+ done
+ ;;
+ json)
+ out "["
+ while read x; do
+ out $sep
+ out_value "$x"
+ sep=","
+ done
+ out "]"
+ ;;
+ esac
+}
+
+function out_value() {
+ # string
+ # number
+ # object
+ # array
+ # 'true'
+ # 'false'
+ # 'null'
+
+ x=$1
+
+ # litterals
+ if [[ "$x" =~ ^(true|false|null)$ ]]; then
+ out "$x"
+ # number
+ elif [[ "$x" =~ ^[+-]?[0-9]+(\.[0-9]+)?$ ]]; then
+ out "$x"
+ # object
+ elif [[ "$x" =~ ^\{.*\}$ ]]; then
+ out "$x"
+ # array
+ elif [[ "$x" =~ ^\[.*\]$ ]]; then
+ out "$x"
+ # string
+ else
+ out "\"$(sed 's/\("\)/\\\1/g' <<<$x)\""
+ fi
+}
+
+function out_comment() {
+ case $format in
+ bash)
+ [[ "$verbose" == 1 ]] && echo "# $@" || true
+ ;;
+ json)
+ ;;
+ esac
+}
+