From c3bf4c7b610df27a2ba5a206456584b7914fcf4f Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 13 Aug 2015 20:45:31 +0200 Subject: [PATCH] correctly merge and reformat custom json into generated config Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_agent/manifest | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest index 053c9e80..76bd6032 100755 --- a/cdist/conf/type/__consul_agent/manifest +++ b/cdist/conf/type/__consul_agent/manifest @@ -126,10 +126,10 @@ if [ -f "$__object/parameter/json-config" ]; then if [ "$json_config" = "-" ]; then json_config="$__object/stdin" fi - printf ',' - # remove trailing , - json=$(cat "$json_config") - echo "${json%*,}" + # remove leading and trailing whitespace and commas from first and last line + # indent each line with 3 spaces for consistency + json=$(sed -e 's/^[ \t]*/ /' -e '1s/^[ \t,]*//' -e '$s/[ \t,]*$//' "$json_config") + printf ' ,%s\n' "$json" fi echo "}" ) | \