diff --git a/bin/idstack-doctor b/bin/idstack-doctor index 8525da3..3bb81b5 100755 --- a/bin/idstack-doctor +++ b/bin/idstack-doctor @@ -135,14 +135,12 @@ elif [ -d "$LEGACY_DIR" ]; then fi if [ -f "$LEGACY_DIR/VERSION" ]; then v=$(tr -d '[:space:]' < "$LEGACY_DIR/VERSION") - # Two arms: explicitly skip modern/future versions first, then flag the - # legacy ones. Mirrors setup. Patterns avoid literal dots and single-digit - # ranges so multi-digit components (2.0.10.0, 2.10.0.0, 20.x, 100.0.0, - # 200.0.0) work. Covered by test/test-version-classifier.sh. - case "$v" in - 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) ;; - 0.*|1.*|2.0.0.*|2.0.0) signature="${signature:+$signature, }VERSION=$v" ;; - esac + # Uses shared classifier to identify pre-v2.0.1.0 versions. Mirrors setup. + # Covered by test/test-version-classifier.sh. + class=$("$IDSTACK_DIR/bin/idstack-version-classifier" "$v") + if [ "$class" = "legacy" ]; then + signature="${signature:+$signature, }VERSION=$v" + fi fi if [ -n "$signature" ]; then echo " PROBLEM: pre-v2.0.1.0 install at $LEGACY_DIR ($signature)" diff --git a/bin/idstack-version-classifier b/bin/idstack-version-classifier new file mode 100755 index 0000000..3caae47 --- /dev/null +++ b/bin/idstack-version-classifier @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Classifies an idstack version string as "skip" (modern), "legacy", or "unknown". +# Used by setup, bin/idstack-doctor, and test/test-version-classifier.sh. + +case "${1:-}" in + 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) echo "skip" ;; + 0.*|1.*|2.0.0.*|2.0.0) echo "legacy" ;; + *) echo "unknown" ;; +esac diff --git a/setup b/setup index ed698ee..4d61bef 100755 --- a/setup +++ b/setup @@ -92,14 +92,12 @@ elif [ -d "$LEGACY_SKILLS_LINK" ] && [ "$LEGACY_SKILLS_LINK" != "$IDSTACK_DIR" ] legacy_is_old_version=0 if [ -f "$LEGACY_SKILLS_LINK/VERSION" ]; then legacy_version=$(tr -d '[:space:]' < "$LEGACY_SKILLS_LINK/VERSION") - # Two arms: explicitly skip modern/future versions first, then flag the - # legacy ones. Patterns avoid literal dots and single-digit ranges so - # multi-digit components (2.0.10.0, 2.10.0.0, 20.x, 100.0.0, 200.0.0) - # work. Covered by test/test-version-classifier.sh. - case "$legacy_version" in - 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) ;; - 0.*|1.*|2.0.0.*|2.0.0) legacy_is_old_version=1 ;; - esac + # Uses shared classifier to identify pre-v2.0.1.0 versions. Covered by + # test/test-version-classifier.sh. + class=$("$IDSTACK_DIR/bin/idstack-version-classifier" "$legacy_version") + if [ "$class" = "legacy" ]; then + legacy_is_old_version=1 + fi fi if [ "$legacy_is_dispatcher" = "1" ] || [ "$legacy_is_old_version" = "1" ]; then if [[ " $* " == *" --keep-legacy "* ]]; then diff --git a/test/test-version-classifier.sh b/test/test-version-classifier.sh index 312d15f..4b38e50 100755 --- a/test/test-version-classifier.sh +++ b/test/test-version-classifier.sh @@ -16,26 +16,18 @@ set -e +IDSTACK_DIR="$(cd "$(dirname "$0")/.." && pwd -P)" + PASS=0 FAIL=0 TOTAL=0 -# Mirror of the case statement in setup and bin/idstack-doctor. Keep these -# patterns in lockstep with both files — if you change one, change all three. -classify_version() { - case "$1" in - 2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) echo "skip" ;; - 0.*|1.*|2.0.0.*|2.0.0) echo "legacy" ;; - *) echo "unknown" ;; - esac -} - check() { TOTAL=$((TOTAL + 1)) local version="$1" local expected="$2" local got - got="$(classify_version "$version")" + got="$("$IDSTACK_DIR/bin/idstack-version-classifier" "$version")" if [ "$got" = "$expected" ]; then PASS=$((PASS + 1)) echo " PASS: $version -> $got"