Skip to content

Commit

Permalink
refactor: Improve version check robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Aug 1, 2024
1 parent 125a2e5 commit e5174b8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,20 @@ trap cleanup EXIT SIGHUP SIGINT
# This function validates the version of a tool.
check_version() {
local tool=$1 threshold=$2 on_error=${3:-die}
local user_version
local user_version user_version_part index
declare -a ver_parts threshold_parts
user_version=$(command $tool --version 2>&1 |
command grep --color=never --extended-regexp --only-matching --regexp='[0-9]+(\.[0-9]+)*' |
command sed q)

IFS='.' read -ra ver_parts <<<"$user_version"
IFS='.' read -ra threshold_parts <<<"$threshold"
for i in "${!threshold_parts[@]}"; do
if ((i >= ${#ver_parts[@]})) || ((ver_parts[i] < threshold_parts[i])); then

for index in "${!threshold_parts[@]}"; do
user_version_part=${ver_parts[index]:-0}
if ((user_version_part < threshold_parts[index])); then
$on_error "Your '$tool' version '$user_version' is insufficient. The minimum required version is '$threshold'."
elif ((ver_parts[i] > threshold_parts[i])); then
elif ((user_version_part > threshold_parts[index])); then
break
fi
done
Expand Down

0 comments on commit e5174b8

Please sign in to comment.