Skip to content

Commit

Permalink
Create output_lib.sh
Browse files Browse the repository at this point in the history
Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>
  • Loading branch information
gitworkflows authored Aug 14, 2024
1 parent c6b69d1 commit ac27698
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions output_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/sh
bldred='\033[1;31m'
bldgrn='\033[1;32m'
bldblu='\033[1;34m'
bldylw='\033[1;33m' # Yellow
txtrst='\033[0m'
first_element=false
section_seperator=""

logit () {
if [ "x$output" != "xJSON" ]; then
printf "%b\n" "$1" | tee -a "$logger"
fi
}

info () {
if [ "x$output" = "xJSON" ]; then
if [ "$first_element" != true ]; then
printf ","
else
first_element=false
fi
printf "{\"result\":\"warn\", \"check_number\":\"$1\", \"check_desc\":\"$2\", \"check_data\":\"$3\"}"
else
printf "%b\n" "${bldblu}[INFO]${txtrst} $1 - $2" | tee -a "$logger"
if [ "$3" != "" ]; then
printf "%b\n" "${bldblu}[INFO]${txtrst} * $3" | tee -a "$logger"
fi
fi
}

pass () {
if [ "x$output" = "xJSON" ]; then
if [ "$first_element" != true ]; then
printf ","
else
first_element=false
fi
printf "{\"result\":\"pass\", \"check_number\":\"$1\", \"check_desc\":\"$2\"}"
else
printf "%b\n" "${bldgrn}[PASS]${txtrst} $1 - $2" | tee -a "$logger"
fi
}

warn () {
if [ "x$output" = "xJSON" ]; then
if [ "$first_element" != true ]; then
printf ","
else
first_element=false
fi
printf "{\"result\":\"warn\", \"check_number\":\"$1\", \"check_desc\":\"$2\", \"check_data\":\"$3\"}"
else
printf "%b\n" "${bldred}[WARN]${txtrst} $1 - $2" | tee -a "$logger"
if [ "$3" != "" ]; then
printf "%b\n" "${bldred}[WARN]${txtrst} * $3" | tee -a "$logger"
fi
fi
}

section_start() {
if [ "x$output" = "xJSON" ]; then
printf "${section_seperator}{\"section\":\"$1\", \"desc\": \"$2\", \"results\":["
first_element=true
section_seperator=","
else
printf "%b\n" "${bldblu}[INFO]${txtrst} $1 - $2" | tee -a "$logger"
fi
}

section_end() {
if [ "x$output" = "xJSON" ]; then
printf "]}"
fi
}

print_start_tests() {
if [ "x$output" = "xJSON" ]; then
printf ", \"tests\":["
fi
}

print_end_tests() {
if [ "x$output" = "xJSON" ]; then
printf "]"
fi
}

print_start_dockerbench() {
if [ "x$output" = "xJSON" ]; then
printf "{\"host\":\"$(hostname)\", \"date\":\"$(date)\""
else
logit "Initializing $(date)\n"
fi
}

print_end_dockerbench() {
if [ "x$output" = "xJSON" ]; then
printf "}\n"
fi
}

yell () {
if [ "x$output" != "xJSON" ]; then
printf "%b\n" "${bldylw}$1${txtrst}\n"
fi
}

0 comments on commit ac27698

Please sign in to comment.