Skip to content

Commit 6e2c912

Browse files
committed
Refactor program_exists and program_must_exist
`program_must_exist` uses `program_exists` now, instead of repeating code. Changed `type` to `command -v` in `program_exists` to be more POSIX compliant. Refactored status code conditional in `program_exists` to remove double negatives. Thanks to @mkwmms for the suggestions.
1 parent 1b08467 commit 6e2c912

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

bootstrap.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@ debug() {
4747

4848
program_exists() {
4949
local ret='0'
50-
type $1 >/dev/null 2>&1 || { local ret='1'; }
50+
command -v $1 >/dev/null 2>&1 || { local ret='1'; }
5151

5252
# fail on non-zero return value
53-
if [ ! "$ret" -eq '0' ]; then
53+
if [ "$ret" -ne 0 ]; then
5454
return 1
5555
fi
5656

5757
return 0
5858
}
5959

6060
program_must_exist() {
61-
local ret='0'
62-
type $1 >/dev/null 2>&1 || { local ret='1'; }
61+
program_exists $1
6362

6463
# throw error on non-zero return value
65-
if [ ! "$ret" -eq '0' ]; then
64+
if [ "$?" -ne 0 ]; then
6665
error "You must have '$1' installed to continue."
6766
fi
6867
}

0 commit comments

Comments
 (0)