@@ -8,6 +8,12 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
88cd ${SCRIPT_DIR}
99source ./common/utils.sh
1010
11+ # logging
12+ VERBOSE=false
13+ log () {
14+ $VERBOSE && echo " $@ " >&2
15+ }
16+
1117# Load variables
1218if [ ! -f " ./load_config.sh" ]; then
1319 echo " [ERROR] load_config.sh not found in the script directory." >&2
@@ -18,7 +24,13 @@ source ./load_config.sh
1824# Check for required commands
1925check_prerequisites
2026
21- # parse arguments
27+ # Parse command line arguments into flags and positional arguments
28+ parse_args flags args " $@ "
29+
30+ if in_array " -v" " ${flags[@]} " ; then
31+ VERBOSE=true
32+ fi
33+
2234operations=(" install" " list-versions" " list-builds" " link" )
2335
2436print_usage () {
@@ -47,8 +59,8 @@ print_usage() {
4759 fi
4860}
4961
50- if [ -z " $1 " ]; then
51- print_usage " $1 "
62+ if [ -z " ${args[0]} " ]; then
63+ print_usage " ${args[0]} "
5264 exit 1
5365fi
5466
@@ -129,18 +141,18 @@ construct_latest_jar_name() {
129141 echo " ${project} -latest.jar"
130142}
131143
132- operation=" $1 "
144+ operation=" ${args[0]} "
133145
134146case " $operation " in
135147install)
136- if [ -z " $2 " ] || [ -z " $3 " ] || [ -z " $4 " ]; then
148+ if [ -z " ${args[1]} " ] || [ -z " ${args[2]} " ] || [ -z " ${args[3]} " ]; then
137149 print_usage " $operation "
138150 exit 1
139151 fi
140152
141- project=" $2 "
142- version=" $3 "
143- build=" $4 "
153+ project=" ${args[1]} "
154+ version=" ${args[2]} "
155+ build=" ${args[3]} "
144156
145157 build_info=$( fetch_api " ${PAPER_API_ENDPOINT} /projects/${project} /versions/${version} /builds/${build} " )
146158 api_jar_name=$( echo " $build_info " |
@@ -170,7 +182,7 @@ install)
170182 chmod +x " ${output_path} "
171183 latest_jar_filename=$( get_latest_build_file " $project " " $version " )
172184 if [ " $latest_jar_filename " == " null" ]; then
173- echo " [ERROR] Unexpected failuer : No latest jar file found for project '$project ' and version '$version '." >&2
185+ echo " [ERROR] Unexpected failure : No latest jar file found for project '$project ' and version '$version '." >&2
174186 exit 1
175187 fi
176188 # ln -sf "${jar_output_directory}/${latest_jar_filename}" "${jar_output_directory}/${project}-latest.jar"
@@ -182,27 +194,27 @@ install)
182194 fi
183195 ;;
184196list-versions)
185- if [ -z " $2 " ]; then
197+ if [ -z " ${args[1]} " ]; then
186198 print_usage " $operation "
187199 exit 1
188200 fi
189201
190- list_versions " $2 "
202+ list_versions " ${args[1]} "
191203 ;;
192204list-builds)
193- if [ -z " $2 " ] || [ -z " $3 " ]; then
205+ if [ -z " ${args[1]} " ] || [ -z " ${args[2]} " ]; then
194206 print_usage " $operation "
195207 exit 1
196208 fi
197209
198- list_builds " $2 " " $3 "
210+ list_builds " ${args[1]} " " ${args[2]} "
199211 ;;
200212link)
201- link_name=" $2 "
202- project=" $3 "
203- version=" $4 "
204- build=" $5 "
205- channel=" $6 "
213+ link_name=" ${args[1]} "
214+ project=" ${args[2]} "
215+ version=" ${args[3]} "
216+ build=" ${args[4]} "
217+ channel=" ${args[5]} "
206218 target_filename=' '
207219 if [ -z " $link_name " ] || [ -z " $project " ] || [ -z " $version " ] || [ -z " $build " ]; then
208220 print_usage " $operation "
@@ -261,11 +273,13 @@ link)
261273 echo " [ERROR] Failed to create symlink '$link_name ' -> '$target_filename '" >&2
262274 exit 1
263275 fi
264- echo " [INFO] Successfully linked '$link_name ' to '$target_filename '" >&2
276+ log " [INFO] Successfully linked '$link_name ' to '$target_filename '" >&2
265277 ;;
266278* )
267279 echo " [ERROR] Unknown operation: $operation " >&2
268280 print_usage
269281 exit 1
270282 ;;
271283esac
284+
285+ exit 0
0 commit comments