From 94267a5d3babc3f924c620b8d1f948af6cd1b83d Mon Sep 17 00:00:00 2001 From: Jongsun Suh <34228073+MajorLift@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:23:30 -0700 Subject: [PATCH] Formatting fixes for `semver.sh` --- scripts/semver.sh | 161 +++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/scripts/semver.sh b/scripts/semver.sh index 89f1bd5e51..3f6d139571 100644 --- a/scripts/semver.sh +++ b/scripts/semver.sh @@ -1,108 +1,107 @@ #!/usr/bin/env bash -# https://github.com/cloudflare/semver_bash/blob/master/semver.sh +# Source: https://github.com/cloudflare/semver_bash/blob/master/semver.sh function semverParseInto() { - local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' - #MAJOR - eval $2=`echo $1 | sed -e "s#$RE#\1#"` - #MINOR - eval $3=`echo $1 | sed -e "s#$RE#\2#"` - #MINOR - eval $4=`echo $1 | sed -e "s#$RE#\3#"` - #SPECIAL - eval $5=`echo $1 | sed -e "s#$RE#\4#"` + local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' + #MAJOR + eval $2=$(echo $1 | sed -e "s#$RE#\1#") + #MINOR + eval $3=$(echo $1 | sed -e "s#$RE#\2#") + #MINOR + eval $4=$(echo $1 | sed -e "s#$RE#\3#") + #SPECIAL + eval $5=$(echo $1 | sed -e "s#$RE#\4#") } function semverEQ() { - local MAJOR_A=0 - local MINOR_A=0 - local PATCH_A=0 - local SPECIAL_A=0 + local MAJOR_A=0 + local MINOR_A=0 + local PATCH_A=0 + local SPECIAL_A=0 - local MAJOR_B=0 - local MINOR_B=0 - local PATCH_B=0 - local SPECIAL_B=0 + local MAJOR_B=0 + local MINOR_B=0 + local PATCH_B=0 + local SPECIAL_B=0 - semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A - semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B + semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A + semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B - if [ $MAJOR_A -ne $MAJOR_B ]; then - return 1 - fi - - if [ $MINOR_A -ne $MINOR_B ]; then - return 1 - fi + if [ $MAJOR_A -ne $MAJOR_B ]; then + return 1 + fi - if [ $PATCH_A -ne $PATCH_B ]; then - return 1 - fi + if [ $MINOR_A -ne $MINOR_B ]; then + return 1 + fi - if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then - return 1 - fi + if [ $PATCH_A -ne $PATCH_B ]; then + return 1 + fi + if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then + return 1 + fi - return 0 + return 0 } function semverLT() { - local MAJOR_A=0 - local MINOR_A=0 - local PATCH_A=0 - local SPECIAL_A=0 - - local MAJOR_B=0 - local MINOR_B=0 - local PATCH_B=0 - local SPECIAL_B=0 - - semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A - semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B - - if [ $MAJOR_A -lt $MAJOR_B ]; then - return 0 - fi - - if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then - return 0 - fi - - if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then - return 0 - fi - - if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then - return 1 - fi - if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then - return 1 - fi - if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then - return 0 - fi - - if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then - return 0 - fi + local MAJOR_A=0 + local MINOR_A=0 + local PATCH_A=0 + local SPECIAL_A=0 + local MAJOR_B=0 + local MINOR_B=0 + local PATCH_B=0 + local SPECIAL_B=0 + + semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A + semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B + + if [ $MAJOR_A -lt $MAJOR_B ]; then + return 0 + fi + + if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then + return 0 + fi + + if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then + return 0 + fi + + if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then return 1 + fi + if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]]; then + return 1 + fi + if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then + return 0 + fi + + if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then + return 0 + fi + + return 1 } function semverGT() { - semverEQ $1 $2 - local EQ=$? + semverEQ $1 $2 + local EQ=$? - semverLT $1 $2 - local LT=$? + semverLT $1 $2 + local LT=$? - if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then - return 0 - else - return 1 - fi + if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then + return 0 + else + return 1 + fi }