Skip to content

Commit 94267a5

Browse files
committed
Formatting fixes for semver.sh
1 parent 0868075 commit 94267a5

File tree

1 file changed

+80
-81
lines changed

1 file changed

+80
-81
lines changed

scripts/semver.sh

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,107 @@
11
#!/usr/bin/env bash
22

3-
# https://github.com/cloudflare/semver_bash/blob/master/semver.sh
3+
# Source: https://github.com/cloudflare/semver_bash/blob/master/semver.sh
44

55
function semverParseInto() {
6-
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
7-
#MAJOR
8-
eval $2=`echo $1 | sed -e "s#$RE#\1#"`
9-
#MINOR
10-
eval $3=`echo $1 | sed -e "s#$RE#\2#"`
11-
#MINOR
12-
eval $4=`echo $1 | sed -e "s#$RE#\3#"`
13-
#SPECIAL
14-
eval $5=`echo $1 | sed -e "s#$RE#\4#"`
6+
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
7+
#MAJOR
8+
eval $2=$(echo $1 | sed -e "s#$RE#\1#")
9+
#MINOR
10+
eval $3=$(echo $1 | sed -e "s#$RE#\2#")
11+
#MINOR
12+
eval $4=$(echo $1 | sed -e "s#$RE#\3#")
13+
#SPECIAL
14+
eval $5=$(echo $1 | sed -e "s#$RE#\4#")
1515
}
1616

1717
function semverEQ() {
18-
local MAJOR_A=0
19-
local MINOR_A=0
20-
local PATCH_A=0
21-
local SPECIAL_A=0
18+
local MAJOR_A=0
19+
local MINOR_A=0
20+
local PATCH_A=0
21+
local SPECIAL_A=0
2222

23-
local MAJOR_B=0
24-
local MINOR_B=0
25-
local PATCH_B=0
26-
local SPECIAL_B=0
23+
local MAJOR_B=0
24+
local MINOR_B=0
25+
local PATCH_B=0
26+
local SPECIAL_B=0
2727

28-
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
29-
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
28+
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
29+
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
3030

31-
if [ $MAJOR_A -ne $MAJOR_B ]; then
32-
return 1
33-
fi
34-
35-
if [ $MINOR_A -ne $MINOR_B ]; then
36-
return 1
37-
fi
31+
if [ $MAJOR_A -ne $MAJOR_B ]; then
32+
return 1
33+
fi
3834

39-
if [ $PATCH_A -ne $PATCH_B ]; then
40-
return 1
41-
fi
35+
if [ $MINOR_A -ne $MINOR_B ]; then
36+
return 1
37+
fi
4238

43-
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
44-
return 1
45-
fi
39+
if [ $PATCH_A -ne $PATCH_B ]; then
40+
return 1
41+
fi
4642

43+
if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
44+
return 1
45+
fi
4746

48-
return 0
47+
return 0
4948

5049
}
5150

5251
function semverLT() {
53-
local MAJOR_A=0
54-
local MINOR_A=0
55-
local PATCH_A=0
56-
local SPECIAL_A=0
57-
58-
local MAJOR_B=0
59-
local MINOR_B=0
60-
local PATCH_B=0
61-
local SPECIAL_B=0
62-
63-
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
64-
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
65-
66-
if [ $MAJOR_A -lt $MAJOR_B ]; then
67-
return 0
68-
fi
69-
70-
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
71-
return 0
72-
fi
73-
74-
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
75-
return 0
76-
fi
77-
78-
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
79-
return 1
80-
fi
81-
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then
82-
return 1
83-
fi
84-
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
85-
return 0
86-
fi
87-
88-
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
89-
return 0
90-
fi
52+
local MAJOR_A=0
53+
local MINOR_A=0
54+
local PATCH_A=0
55+
local SPECIAL_A=0
9156

57+
local MAJOR_B=0
58+
local MINOR_B=0
59+
local PATCH_B=0
60+
local SPECIAL_B=0
61+
62+
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
63+
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
64+
65+
if [ $MAJOR_A -lt $MAJOR_B ]; then
66+
return 0
67+
fi
68+
69+
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
70+
return 0
71+
fi
72+
73+
if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
74+
return 0
75+
fi
76+
77+
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then
9278
return 1
79+
fi
80+
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]]; then
81+
return 1
82+
fi
83+
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then
84+
return 0
85+
fi
86+
87+
if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
88+
return 0
89+
fi
90+
91+
return 1
9392

9493
}
9594

9695
function semverGT() {
97-
semverEQ $1 $2
98-
local EQ=$?
96+
semverEQ $1 $2
97+
local EQ=$?
9998

100-
semverLT $1 $2
101-
local LT=$?
99+
semverLT $1 $2
100+
local LT=$?
102101

103-
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
104-
return 0
105-
else
106-
return 1
107-
fi
102+
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
103+
return 0
104+
else
105+
return 1
106+
fi
108107
}

0 commit comments

Comments
 (0)