Skip to content

Commit

Permalink
Use read command to test if there is any data on stdin & redirect to…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
kasia-kujawa authored Nov 24, 2020
1 parent d6c5b95 commit 4ee5b4e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/commands/template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ function print_help() {
echo "K8S template generator"
}

function echoerr() {
echo "${1}" >&2
}

readonly arg=${1}

if [[ "${arg}" == "--help" ]]; then
Expand All @@ -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}"

0 comments on commit 4ee5b4e

Please sign in to comment.