Skip to content

Commit

Permalink
Add "fail" function to utils
Browse files Browse the repository at this point in the history
The function prints an error message to stderr and exits or returns with
a code of 1 based on the fail mode, which is passed as an input. If the
file is being sourced, then "return" would be passed in; else "exit"
would be passed in. This function invokes the say function created
earlier with the error formatting mode.
  • Loading branch information
sudotensor committed Aug 2, 2021
1 parent 4d95793 commit a58f3b9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ say () {
*) # Unknown error
;;
esac
}

# Prints an error message to stderr and exits (or returns) with a code of 1
fail () {
local mode=${1}
local msg=( "${@:2}" )
say error "${msg[@]}"
$mode 1
}

0 comments on commit a58f3b9

Please sign in to comment.