Skip to content

Commit bbab3fa

Browse files
committed
Merge branch 'feature/useage-output' into develop
2 parents 0048047 + 9573ba9 commit bbab3fa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

argument-parser.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ argGetName() {
7373
exit 1
7474
}
7575

76+
argList() {
77+
echo "ARGUMENT SUMMARY:"
78+
for arguments in "${!argExpected[@]}"; do
79+
80+
local argumentsPrefixed=()
81+
82+
# Take all the arguments and prefix them with hyphens
83+
while IFS='|' read -ra argumentArray; do
84+
for argument in "${argumentArray[@]}"; do
85+
86+
# Add the hyphens
87+
if [[ ${#argument} -gt 1 ]]; then
88+
argumentsPrefixed+=("--$argument")
89+
else
90+
argumentsPrefixed+=("-$argument")
91+
fi
92+
done
93+
done <<< "$arguments"
94+
95+
regexArgName=".+ - (.+)"
96+
[[ "${argExpected[$arguments]}" =~ $regexArgName ]]
97+
98+
local argumentList="${argumentsPrefixed[@]}"
99+
local argumentDesc="${BASH_REMATCH[1]}"
100+
echo " $argumentList"
101+
echo " $argumentDesc"
102+
echo
103+
done
104+
}
105+
76106
argUnexpected() {
77107
echo "UNEXPECTED ARGUMENT $1"
78108
}
@@ -202,4 +232,5 @@ argParse() {
202232
# If we are accessing this script directly run the argument parser, useful for testing
203233
if [ "$0" == "$BASH_SOURCE" ]; then
204234
argParse
235+
argList
205236
fi

0 commit comments

Comments
 (0)