Skip to content

Commit

Permalink
Add log_info bash function
Browse files Browse the repository at this point in the history
* Adds a function to output logs in a standard format.
* `-q` can be used to supress the output, allowing a common variable
  (eg. QUIET_MODE) to be used, rather than using `if` everywhere to
  check for verbose-ness.
* eg. `log_info "Something happened :)" -q "$QUIET_MODE"`
  • Loading branch information
Stretch96 committed Nov 14, 2023
1 parent 02d6769 commit 70ba908
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/bash-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ function err {
echo "[!] Error: $*" >&2
}

# Set up a handy log output function
#
# @usage log_info -l 'Something happened :)'"
# @param -l <log> Any information to output
# @param -q <0/1> Quiet mode
function log_info {
OPTIND=1
QUIET_MODE=0
while getopts "l:q:" opt; do
case $opt in
l)
LOG="$OPTARG"
;;
q)
QUIET_MODE="$OPTARG"
;;
*)
echo "Invalid \`log_info\` function usage" >&2
exit 1
;;
esac
done
if [ "$QUIET_MODE" == "0" ]
then
echo "==> $LOG"
fi
}

# Check to see if a binary is installed on the system
#
# @usage is_installed "oathtool"
Expand Down

0 comments on commit 70ba908

Please sign in to comment.