Skip to content

Commit

Permalink
refactor(Bash): abstract now() function
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Oct 26, 2020
1 parent b6bd88d commit c7e2c2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
13 changes: 9 additions & 4 deletions .travis/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
# Pass arguments into a function
# https://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
function now() {
nowVariable=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)
echo "$nowVariable"
}

function printInfo() {
echo -e "$NOW \e[32m INFO --- $1\e[0m"
echo -e "$(now) \e[32m INFO --- $1\e[0m"
return 0
}

function printWarn() {
echo -e "$NOW \e[33m WARN --- $1\e[0m"
echo -e "$(now) \e[33m WARN --- $1\e[0m"
return 0
}

function printError() {
echo -e "$NOW \e[31mERROR --- $1\e[0m"
echo -e "$(now) \e[31mERROR --- $1\e[0m"
return 0
}

export -f printInfo
export -f printInfo printWarn printError
14 changes: 9 additions & 5 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
# https://stackoverflow.com/questions/19622198/what-does-set-e-mean-in-a-bash-script
set -e

NOW=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)

########################## Functions Declaration ##########################
# Bash tips: Colors and formatting (ANSI/VT100 Control sequences)
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
# Pass arguments into a function
# https://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
function now() {
nowVariable=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)
echo "$nowVariable"
}

function printInfo() {
echo -e "$NOW \e[32m INFO --- $1\e[0m"
echo -e "$(now) \e[32m INFO --- $1\e[0m"
return 0
}

function printWarn() {
echo -e "$NOW \e[33m WARN --- $1\e[0m"
echo -e "$(now) \e[33m WARN --- $1\e[0m"
return 0
}

function printError() {
echo -e "$NOW \e[31mERROR --- $1\e[0m"
echo -e "$(now) \e[31mERROR --- $1\e[0m"
return 0
}

Expand Down
11 changes: 8 additions & 3 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ NOW=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
# Pass arguments into a function
# https://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
function now() {
nowVariable=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)
echo "$nowVariable"
}

function printInfo() {
echo -e "$NOW \e[32m INFO --- $1\e[0m"
echo -e "$(now) \e[32m INFO --- $1\e[0m"
return 0
}

function printWarn() {
echo -e "$NOW \e[33m WARN --- $1\e[0m"
echo -e "$(now) \e[33m WARN --- $1\e[0m"
return 0
}

function printError() {
echo -e "$NOW \e[31mERROR --- $1\e[0m"
echo -e "$(now) \e[31mERROR --- $1\e[0m"
return 0
}

Expand Down

0 comments on commit c7e2c2a

Please sign in to comment.