File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 2020# --debug 3
2121DEBUG_LEVEL=" $( argValue " debug" ) " # 3
2222
23+ # --max-size=1024
24+ MAX_SIZE=" $( argValue " max-size" ) " # 1024
25+
2326# -R 0
2427[ " $( argValue " R" ) " == " 0" ] && echo " Recursive depth 0"
2528
@@ -58,6 +61,11 @@ if argExists 'long-argument-name'; then
5861 # Do something awesome
5962fi
6063
64+ # --protocol=HTTP
65+ if argExists ' protocol' ; then
66+ # Do something awesome
67+ fi
68+
6169# -O 43
6270argExists ' r' && echo " Found the -O argument"
6371```
@@ -92,6 +100,18 @@ newlines"
92100--365 " days"
93101```
94102
103+ ### Long Form With Value
104+
105+ ``` bash
106+ --lang=" en"
107+ --crawl=false
108+ --match-pattern=" .+"
109+ --newline="
110+ "
111+ --UpperCase=sensitive
112+ --45=" 25+20"
113+ ```
114+
95115### Chained Short Form Arguments
96116
97117``` bash
Original file line number Diff line number Diff line change 44regexArgShort=' ^-([a-zA-Z0-9])$'
55regexArgShortChained=' ^-([a-zA-Z0-9]{2,})$'
66regexArgLong=' ^--([a-zA-Z0-9\-]{2,})$'
7+ regexArgLongWithValue=' ^--([a-zA-Z0-9\-]{2,})=(.*)$'
78
89argChunks=()
910
@@ -63,6 +64,20 @@ for argChunk in "${argChunks[@]}"; do
6364 continue ;
6465 fi
6566
67+ # Check if this chunk is a long form with value argument
68+ [[ $argChunk =~ $regexArgLongWithValue ]]
69+ if [ " ${BASH_REMATCH[1]} " != " " ]; then
70+ argument=" ${BASH_REMATCH[1]} "
71+ lastArgument=" $argument "
72+
73+ # Add the argument to the arguments array
74+ args[" ${BASH_REMATCH[1]} " ]=" ${BASH_REMATCH[2]} "
75+
76+ [ $ARG_DEBUG == true ] && echo " Argument (long with value): ${BASH_REMATCH[1]} =${BASH_REMATCH[2]} "
77+
78+ continue ;
79+ fi
80+
6681 # Check if this chunk is a long form argument
6782 [[ $argChunk =~ $regexArgLong ]]
6883 if [ " ${BASH_REMATCH[1]} " != " " ]; then
You can’t perform that action at this time.
0 commit comments