Skip to content

Commit cc0276a

Browse files
authored
Clean up command-line parsing code (#1948)
1 parent 2ad31f5 commit cc0276a

File tree

1 file changed

+12
-48
lines changed

1 file changed

+12
-48
lines changed

main.sh

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,13 @@ cmdline() {
280280
if [ "$OPTION" = "-" ]; then # long option: reformulate OPTION and OPTARG
281281
OPTION="${OPTARG}" # extract long option name
282282
OPTARG=''
283+
if [[ -n ${!OPTIND-} ]]; then
284+
OPTARG="${!OPTIND}"
285+
OPTIND=$((OPTIND + 1))
286+
fi
283287
fi
284288
case ${OPTION} in
285-
add)
286-
if [[ -n ${!OPTIND-} ]]; then
287-
OPTARG="${!OPTIND}"
288-
OPTIND=$((OPTIND + 1))
289-
fi
290-
;&
291-
a)
289+
a | add)
292290
if [[ -n ${OPTARG-} ]]; then
293291
local MULTIOPT
294292
MULTIOPT=("$OPTARG")
@@ -303,13 +301,7 @@ cmdline() {
303301
exit 1
304302
fi
305303
;;
306-
compose)
307-
if [[ -n ${!OPTIND-} ]]; then
308-
OPTARG="${!OPTIND}"
309-
OPTIND=$((OPTIND + 1))
310-
fi
311-
;&
312-
c)
304+
c | compose)
313305
if [[ -n ${OPTARG-} ]]; then
314306
case ${OPTARG} in
315307
generate | merge) ;&
@@ -376,10 +368,6 @@ cmdline() {
376368
fi
377369
;;
378370
env-set | env-set-lower)
379-
if [[ -n ${!OPTIND-} ]]; then
380-
OPTARG="${!OPTIND}"
381-
OPTIND=$((OPTIND + 1))
382-
fi
383371
readonly ENVMETHOD=${OPTION}
384372
if [[ -z ${ENVVAR-} ]]; then
385373
readonly ENVARG=${OPTARG}
@@ -417,13 +405,7 @@ cmdline() {
417405
p | prune)
418406
readonly PRUNE=true
419407
;;
420-
remove)
421-
if [[ -n ${!OPTIND-} ]]; then
422-
OPTARG="${!OPTIND}"
423-
OPTIND=$((OPTIND + 1))
424-
fi
425-
;&
426-
r)
408+
r | remove)
427409
if [[ -n ${OPTARG-} ]]; then
428410
local MULTIOPT
429411
MULTIOPT=("$OPTARG")
@@ -439,7 +421,7 @@ cmdline() {
439421
fi
440422
;;
441423
status-*)
442-
if [[ -n ${!OPTIND-} ]]; then
424+
if [[ -n ${OPTARG-} ]]; then
443425
readonly STATUSMETHOD=${OPTION}
444426
local MULTIOPT
445427
MULTIOPT=("$OPTARG")
@@ -454,13 +436,7 @@ cmdline() {
454436
exit 1
455437
fi
456438
;;
457-
status)
458-
if [[ -n ${!OPTIND-} ]]; then
459-
OPTARG="${!OPTIND}"
460-
OPTIND=$((OPTIND + 1))
461-
fi
462-
;&
463-
s)
439+
s | status)
464440
if [[ -n ${OPTARG-} ]]; then
465441
readonly STATUSMETHOD='status'
466442
local MULTIOPT
@@ -476,13 +452,7 @@ cmdline() {
476452
exit 1
477453
fi
478454
;;
479-
test)
480-
if [[ -n ${!OPTIND-} ]]; then
481-
OPTARG="${!OPTIND}"
482-
OPTIND=$((OPTIND + 1))
483-
fi
484-
;&
485-
t)
455+
t | test)
486456
if [[ -n ${OPTARG-} ]]; then
487457
readonly TEST=${OPTARG}
488458
else
@@ -492,21 +462,15 @@ cmdline() {
492462
;;
493463
theme)
494464
readonly THEMEMETHOD='theme'
495-
if [[ -n ${!OPTIND-} ]]; then
465+
if [[ -n ${OPTARG-} ]]; then
496466
readonly THEME="${!OPTIND}"
497467
OPTIND=$((OPTIND + 1))
498468
fi
499469
;;
500470
theme-*)
501471
readonly THEMEMETHOD=${OPTION}
502472
;;
503-
update)
504-
if [[ -n ${!OPTIND-} ]]; then
505-
OPTARG="${!OPTIND}"
506-
OPTIND=$((OPTIND + 1))
507-
fi
508-
;&
509-
u)
473+
u | update)
510474
UPDATE=true
511475
if [[ -n ${OPTARG-} ]]; then
512476
UPDATE="${OPTARG}"

0 commit comments

Comments
 (0)