Skip to content

Commit 868f0f6

Browse files
committed
Moved the variable declaration to the top of the parser and explicitly set the values to argv, argExpected and argChunks to empty arrays
1 parent 559225a commit 868f0f6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

argument-parser.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ regexArgLongWithValue='^--([a-zA-Z0-9\-]{2,})=(.*)$'
88

99
regexArgDefault='^([^=]+)=(.+) -'
1010

11+
# Initialise some variables
12+
declare -A argv;
13+
argv=()
14+
declare -A argExpected
15+
argExpected=()
16+
declare -a argChunks
1117
argChunks=()
1218

19+
lastWasArgument=0
20+
lastArgument=""
21+
1322
# Expand chained short form arguments, eg -aih => -a -i -h
1423
for argChunk in "$@"; do
1524

@@ -41,13 +50,6 @@ done
4150

4251
[ "$ARG_DEBUG" == true ] && echo "Expanded argument list: ${argChunks[@]}"
4352

44-
# Initialise some variables
45-
declare -A argv
46-
lastWasArgument=0
47-
lastArgument=""
48-
49-
declare -A argExpected
50-
5153
argGetName() {
5254
for k in "${!argExpected[@]}"
5355
do

0 commit comments

Comments
 (0)