Skip to content

Commit

Permalink
Fixed tty detection for output redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
WoozyMasta committed Feb 17, 2021
1 parent 63723b3 commit a420826
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.

* Fixed issue with relative paths #6
* Fixed force remove resorces dirs in data dir #7
* Fixed tty detection for output redirects, show plain log messages if not use
interactive seesion or redirect output to file
## [1.0.1] - 2021-02-17

### Changed
Expand Down
15 changes: 7 additions & 8 deletions kube-dump
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,43 @@
set -e

# Messages
[ -t 0 ] && _tty=1 || _tty=0
log () {
printf '%s [%s] %s\n' "$(date '+%Y/%m/%d %H:%M:%S')" "$1" "${@:2}"
}
msg-start () {
[ "$silent" == 'true' ] && return; if [ "$_tty" -eq 1 ]; then
[ "$silent" == 'true' ] && return; if [ -t 1 ]; then
printf '\e[1;33m%-15s\e[m%-30s%s\n' 'Processing' "$1" "${@:2}"
else log INFO "Processing dump $*"; fi
}
msg-end () {
[ "$silent" == 'true' ] && return; if [ "$_tty" -eq 1 ]; then
[ "$silent" == 'true' ] && return; if [ -t 1 ]; then
printf '\e[1A\e[1;32m%-15s\e[m%-30s%s\n' 'Success' "$1" "${@:2}"
else log INFO "Successfully dumped $*"; fi
}
msg-fail () {
[ "$silent" == 'true' ] && return; if [ "$_tty" -eq 1 ]; then
[ "$silent" == 'true' ] && return; if [ -t 1 ]; then
printf '\e[1A\e[1;31m%-15s\e[m%-30s%s\n' 'Fail' "$1" "${@:2}"
else log WARNING "Failed dump $*"; fi
}
success () {
[ "$silent" == 'true' ] && return; if [ "$_tty" -eq 1 ]; then
[ "$silent" == 'true' ] && return; if [ -t 1 ]; then
printf '%s \e[1;36m%s\e[m %s\n' "$1" "$2" "${@:3}"
else log INFO "$*"; fi
score=$((score+1))
}
heading () {
[ "$silent" == 'true' ] && return; if [ "$_tty" -eq 1 ]; then
[ "$silent" == 'true' ] && return; if [ -t 1 ]; then
printf '%s \e[1;34m%s\e[m %s\n%-15s%-30s%s\n' \
"$1" "$2" 'started' 'STATE' 'RESOURCE' 'NAME'
else log INFO "$*"; fi
}
warn () {
if [ "$_tty" -eq 1 ]; then
if [ -t 1 ]; then
>&2 printf '\e[1;31m%-10s\e[m%s\n' 'Warning:' "$*"
else log WARNING "$*"; fi
}
fail () {
if [ "$_tty" -eq 1 ]; then
if [ -t 1 ]; then
>&2 printf '\n\e[1;31m%-10s\e[m%s\n' 'Error:' "$*"; exit 1
else log ERROR "$*"; exit 1; fi
}
Expand Down

0 comments on commit a420826

Please sign in to comment.