Skip to content

Commit edb6d10

Browse files
committed
Added a prefixed argument summary list
1 parent fc05af8 commit edb6d10

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

argument-parser.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,28 @@ argGetName() {
7474
}
7575

7676
argList() {
77-
echo "ARGUMENTS:"
78-
for arguments in "${!argExpected[@]}"
79-
do
77+
echo "ARGUMENT SUMMARY:"
78+
for arguments in "${!argExpected[@]}"; do
79+
80+
# Take all the arguments and prefix them with hyphens
81+
while IFS='|' read -ra argumentArray; do
82+
for argument in "${argumentArray[@]}"; do
83+
84+
# Add the hyphens
85+
if [[ ${#argument} -gt 1 ]]; then
86+
argumentsPrefixed+=("--$argument")
87+
else
88+
argumentsPrefixed+=("-$argument")
89+
fi
90+
done
91+
done <<< "$arguments"
8092

8193
regexArgName="(.+) - (.+)"
8294
[[ "${argExpected[$arguments]}" =~ $regexArgName ]]
8395

84-
local argumentName="${BASH_REMATCH[1]}"
96+
local argumentList="${argumentsPrefixed[@]}"
8597
local argumentDesc="${BASH_REMATCH[2]}"
86-
echo " $arguments ($argumentName)"
87-
echo " $argumentDesc"
98+
echo "$argumentList $argumentDesc" | column -ts $'\t'
8899
done
89100
}
90101

@@ -216,7 +227,7 @@ argParse() {
216227

217228
# If we are accessing this script directly run the argument parser, useful for testing
218229
if [ "$0" == "$BASH_SOURCE" ]; then
219-
argExpected['t']="test - this is a test"
230+
argExpected['t|a|test']="test - this is a test"
220231
argParse
221232
argList
222233
fi

0 commit comments

Comments
 (0)