@@ -87,41 +87,56 @@ 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; return 0
90+ echo -1
91+ return 0
9192 elif [[ $diff -gt 0 ]]; then
92- echo 1; return 0
93+ echo 1
94+ return 0
9395 fi
9496 done
9597
9698 # PREREL should compare with the ASCII order.
9799 if [[ -z " ${V[3]} " ]] && [[ -n " ${V_[3]} " ]]; then
98- echo 1; return 0;
100+ echo 1
101+ return 0
99102 elif [[ -n " ${V[3]} " ]] && [[ -z " ${V_[3]} " ]]; then
100- echo -1; return 0;
103+ echo -1
104+ return 0
101105 elif [[ -n " ${V[3]} " ]] && [[ -n " ${V_[3]} " ]]; then
102106 if [[ " ${V[3]} " > " ${V_[3]} " ]]; then
103- echo 1; return 0;
107+ echo 1
108+ return 0
104109 elif [[ " ${V[3]} " < " ${V_[3]} " ]]; then
105- echo -1; return 0;
110+ echo -1
111+ return 0
106112 fi
107113 fi
108114
109115 echo 0
110116}
111117
112118function command-bump {
113- local new; local version; local sub_version; local command ;
119+ local new
120+ local version
121+ local sub_version
122+ local command
114123
115124 case $# in
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;;
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 ;;
125140 esac
126141
127142 validate-version " $version " parts
@@ -133,68 +148,89 @@ function command-bump {
133148 local build=" ${parts[4]} "
134149
135150 case " $command " in
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 ;;
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 ;;
143158 esac
144159
145160 echo " $new "
146161 exit 0
147162}
148163
149164function command-compare {
150- local v; local v_;
165+ local v
166+ local v_
151167
152168 case $# in
153- 2) v=$( validate-version " $1 " ) ; v_=$( validate-version " $2 " ) ;;
154- * ) usage-help ;;
169+ 2)
170+ v=$( validate-version " $1 " )
171+ v_=$( validate-version " $2 " )
172+ ;;
173+ * ) usage-help ;;
155174 esac
156175
157176 compare-version " $v " " $v_ "
158177 exit 0
159178}
160179
161-
162180# shellcheck disable=SC2034
163181function command-get {
164- local part version
182+ local part version
165183
166- if [[ " $# " -ne " 2" ]] || [[ -z " $1 " ]] || [[ -z " $2 " ]]; then
167- usage-help
168- exit 0
169- fi
184+ if [[ " $# " -ne " 2" ]] || [[ -z " $1 " ]] || [[ -z " $2 " ]]; then
185+ usage-help
186+ exit 0
187+ fi
170188
171- part=" $1 "
172- version=" $2 "
189+ part=" $1 "
190+ version=" $2 "
173191
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} "
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} "
180198
181- case " $part " in
182- major|minor|patch| release| prerel| build) echo " ${! part} " ;;
183- * ) usage-help ;;
184- esac
199+ case " $part " in
200+ major | minor | patch | release | prerel | build) echo " ${! part} " ;;
201+ * ) usage-help ;;
202+ esac
185203
186- exit 0
204+ exit 0
187205}
188206
189207case $# in
190- 0) echo " Unknown command: $* " ; usage-help;;
208+ 0)
209+ echo " Unknown command: $* "
210+ usage-help
211+ ;;
191212esac
192213
193214case $1 in
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;;
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+ ;;
200236esac
0 commit comments