Skip to content

Commit

Permalink
Avoid duplication of command -v
Browse files Browse the repository at this point in the history
  • Loading branch information
t-botz committed Mar 8, 2018
1 parent 299427a commit faa08bd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,16 @@ err() {
}

need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
if ! check_cmd "$1"
then err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" > /dev/null 2>&1
return $?
}

need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
Expand All @@ -362,9 +367,9 @@ ignore() {
# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
if command -v curl > /dev/null 2>&1
if check_cmd curl
then _dld=curl
elif command -v wget > /dev/null 2>&1
elif check_cmd wget
then _dld=wget
else _dld='curl or wget' # to be used in error message of need_cmd
fi
Expand Down

0 comments on commit faa08bd

Please sign in to comment.