@@ -87,56 +87,41 @@ function compare-version {
8787 for i in 0 1 2; do
8888 local diff=$(( ${V[$i]} - ${V_[$i]} ))
8989 if [[ $diff -lt 0 ]]; then
90- echo -1
91- return 0
90+ echo -1; return 0
9291 elif [[ $diff -gt 0 ]]; then
93- echo 1
94- return 0
92+ echo 1; return 0
9593 fi
9694 done
9795
9896 # PREREL should compare with the ASCII order.
9997 if [[ -z " ${V[3]} " ]] && [[ -n " ${V_[3]} " ]]; then
100- echo 1
101- return 0
98+ echo 1; return 0;
10299 elif [[ -n " ${V[3]} " ]] && [[ -z " ${V_[3]} " ]]; then
103- echo -1
104- return 0
100+ echo -1; return 0;
105101 elif [[ -n " ${V[3]} " ]] && [[ -n " ${V_[3]} " ]]; then
106102 if [[ " ${V[3]} " > " ${V_[3]} " ]]; then
107- echo 1
108- return 0
103+ echo 1; return 0;
109104 elif [[ " ${V[3]} " < " ${V_[3]} " ]]; then
110- echo -1
111- return 0
105+ echo -1; return 0;
112106 fi
113107 fi
114108
115109 echo 0
116110}
117111
118112function command-bump {
119- local new
120- local version
121- local sub_version
122- local command
113+ local new; local version; local sub_version; local command ;
123114
124115 case $# in
125- 2) case $1 in
126- major | minor | patch | release)
127- command=$1
128- version=$2
129- ;;
130- * ) usage-help ;;
131- esac ;;
132- 3) case $1 in
133- prerel | build)
134- command=$1
135- sub_version=$2 version=$3
136- ;;
137- * ) usage-help ;;
138- esac ;;
139- * ) usage-help ;;
116+ 2) case $1 in
117+ major|minor|patch|release) command=$1 ; version=$2 ;;
118+ * ) usage-help;;
119+ esac ;;
120+ 3) case $1 in
121+ prerel|build) command=$1 ; sub_version=$2 version=$3 ;;
122+ * ) usage-help;;
123+ esac ;;
124+ * ) usage-help;;
140125 esac
141126
142127 validate-version " $version " parts
@@ -148,89 +133,68 @@ function command-bump {
148133 local build=" ${parts[4]} "
149134
150135 case " $command " in
151- major) new=" $(( major + 1 )) .0.0" ;;
152- minor) new=" ${major} .$(( minor + 1 )) .0" ;;
153- patch) new=" ${major} .${minor} .$(( patch + 1 )) " ;;
154- release) new=" ${major} .${minor} .${patch} " ;;
155- prerel) new=$( validate-version " ${major} .${minor} .${patch} -${sub_version} " ) ;;
156- build) new=$( validate-version " ${major} .${minor} .${patch}${prere} +${sub_version} " ) ;;
157- * ) usage-help ;;
136+ major) new=" $(( major + 1 )) .0.0" ;;
137+ minor) new=" ${major} .$(( minor + 1 )) .0" ;;
138+ patch) new=" ${major} .${minor} .$(( patch + 1 )) " ;;
139+ release) new=" ${major} .${minor} .${patch} " ;;
140+ prerel) new=$( validate-version " ${major} .${minor} .${patch} -${sub_version} " ) ;;
141+ build) new=$( validate-version " ${major} .${minor} .${patch}${prere} +${sub_version} " ) ;;
142+ * ) usage-help ;;
158143 esac
159144
160145 echo " $new "
161146 exit 0
162147}
163148
164149function command-compare {
165- local v
166- local v_
150+ local v; local v_;
167151
168152 case $# in
169- 2)
170- v=$( validate-version " $1 " )
171- v_=$( validate-version " $2 " )
172- ;;
173- * ) usage-help ;;
153+ 2) v=$( validate-version " $1 " ) ; v_=$( validate-version " $2 " ) ;;
154+ * ) usage-help ;;
174155 esac
175156
176157 compare-version " $v " " $v_ "
177158 exit 0
178159}
179160
161+
180162# shellcheck disable=SC2034
181163function command-get {
182- local part version
164+ local part version
183165
184- if [[ " $# " -ne " 2" ]] || [[ -z " $1 " ]] || [[ -z " $2 " ]]; then
185- usage-help
186- exit 0
187- fi
166+ if [[ " $# " -ne " 2" ]] || [[ -z " $1 " ]] || [[ -z " $2 " ]]; then
167+ usage-help
168+ exit 0
169+ fi
188170
189- part=" $1 "
190- version=" $2 "
171+ part=" $1 "
172+ version=" $2 "
191173
192- validate-version " $version " parts
193- local major=" ${parts[0]} "
194- local minor=" ${parts[1]} "
195- local patch=" ${parts[2]} "
196- local prerel=" ${parts[3]: 1} "
197- local build=" ${parts[4]: 1} "
174+ validate-version " $version " parts
175+ local major=" ${parts[0]} "
176+ local minor=" ${parts[1]} "
177+ local patch=" ${parts[2]} "
178+ local prerel=" ${parts[3]: 1} "
179+ local build=" ${parts[4]: 1} "
198180
199- case " $part " in
200- major | minor | patch | release | prerel | build) echo " ${! part} " ;;
201- * ) usage-help ;;
202- esac
181+ case " $part " in
182+ major|minor|patch| release| prerel| build) echo " ${! part} " ;;
183+ * ) usage-help ;;
184+ esac
203185
204- exit 0
186+ exit 0
205187}
206188
207189case $# in
208- 0)
209- echo " Unknown command: $* "
210- usage-help
211- ;;
190+ 0) echo " Unknown command: $* " ; usage-help;;
212191esac
213192
214193case $1 in
215- --help | -h)
216- echo -e " $USAGE "
217- exit 0
218- ;;
219- --version | -v) usage-version ;;
220- bump)
221- shift
222- command-bump " $@ "
223- ;;
224- get)
225- shift
226- command-get " $@ "
227- ;;
228- compare)
229- shift
230- command-compare " $@ "
231- ;;
232- * )
233- echo " Unknown arguments: $* "
234- usage-help
235- ;;
194+ --help|-h) echo -e " $USAGE " ; exit 0;;
195+ --version|-v) usage-version ;;
196+ bump) shift ; command-bump " $@ " ;;
197+ get) shift ; command-get " $@ " ;;
198+ compare) shift ; command-compare " $@ " ;;
199+ * ) echo " Unknown arguments: $* " ; usage-help;;
236200esac
0 commit comments