From 4e9d3f77009b111240756bae64da420c570c42ee Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Wed, 13 May 2015 12:59:04 -0700 Subject: [PATCH] Use color in pre-commit --- hooks/pre-commit | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 2f0eec9457..3a240b3d14 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,5 +1,9 @@ #!/bin/bash +readonly reset=$(tput sgr0) +readonly red=$(tput bold; tput setaf 1) +readonly green=$(tput bold; tput setaf 2) + KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")" exit_code=0 @@ -16,15 +20,15 @@ for file in "${files[@]}"; do done if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then - echo "ERROR!" + echo "${red}ERROR!" echo "Some files have not been gofmt'd. To fix these errors, " echo "cut and paste the following:" echo " gofmt -s -w ${files_need_gofmt[@]}" exit_code=1 else - echo "OK" + echo "${green}OK" fi -echo +echo "${reset}" echo -ne "Checking for files that need boilerplate... " files_need_boilerplate=() @@ -47,7 +51,7 @@ if [[ ${#files} -gt 0 ]]; then fi if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; then - echo "ERROR!" + echo "${red}ERROR!" echo "Some files are missing the required boilerplate header" echo "from hooks/boilerplate.txt:" for file in "${files_need_boilerplate[@]}"; do @@ -55,9 +59,9 @@ if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; then done exit_code=1 else - echo "OK" + echo "${green}OK" fi -echo +echo "${reset}" echo -ne "Checking for API descriptions... " files_need_description=() @@ -71,7 +75,7 @@ for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v done if [[ "${#files_need_description[@]}" -ne 0 ]]; then - echo "ERROR!" + echo "${red}ERROR!" echo "Some API files are missing the required field descriptions." echo "Add description tags to all non-inline fields in the following files:" for file in "${files_need_description[@]}"; do @@ -79,20 +83,20 @@ if [[ "${#files_need_description[@]}" -ne 0 ]]; then done exit_code=1 else - echo "OK" + echo "${green}OK" fi -echo +echo "${reset}" echo -ne "Checking for docs that need updating... " if ! hack/verify-gendocs.sh > /dev/null; then - echo "ERROR!" + echo "${red}ERROR!" echo "Some docs are out of sync between CLI and markdown." echo "To regenerate docs, run:" echo " hack/run-gendocs.sh > docs/kubectl.md" exit_code=1 else - echo "OK" + echo "${green}OK" fi -echo +echo "${reset}" exit $exit_code