From 4ee5b4e780341a4e6ef9f1167e6af690f094e5c6 Mon Sep 17 00:00:00 2001 From: Katarzyna Kujawa <73836361+kkujawa-sumo@users.noreply.github.com> Date: Tue, 24 Nov 2020 12:25:43 +0100 Subject: [PATCH] Use read command to test if there is any data on stdin & redirect to stderr (#77) * Use read command to test if there is any data on stdin * Redirect messages to stderr * Add echo_stderr function * Fix style, change echo_stderr to echoerr --- src/commands/template | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/template b/src/commands/template index d7340e43..8f8c659b 100755 --- a/src/commands/template +++ b/src/commands/template @@ -4,6 +4,10 @@ function print_help() { echo "K8S template generator" } +function echoerr() { + echo "${1}" >&2 +} + readonly arg=${1} if [[ "${arg}" == "--help" ]]; then @@ -17,15 +21,15 @@ readonly REPO_URL="${REPO_URL:-https://sumologic.github.io/sumologic-kubernetes- # Take data from stdin if available and put into tmpfile tmpfile="$(mktemp /tmp/values.yaml.XXXXXX)" extra_params='' -if [ ! -t 0 ]; then +if [ ! read -t 0 ]; then cat <&0 > "${tmpfile}" extra_params="-f${tmpfile}" fi -echo '# Add sumologic repository' +echoerr '# Add sumologic repository' helm repo add sumologic "${REPO_URL}" 1>/dev/null 2>&1 -echo '# Update repository' +echoerr '# Update repository' helm repo update 1>/dev/null 2>&1 -echo '# Generating template' +echoerr '# Generating template' helm template "${REPO_PATH}" ${extra_params} "$@" 2>&1 | grep -vE '^manifest_sorter.go' rm "${tmpfile}"