Skip to content

Commit ad958cc

Browse files
committed
add tests for advanced flag notation
1 parent 6a57c72 commit ad958cc

File tree

31 files changed

+177
-106
lines changed

31 files changed

+177
-106
lines changed

examples/catch-all-advanced/cli

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ normalize_input() {
139139

140140
while [[ $# -gt 0 ]]; do
141141
arg="$1"
142-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
142+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
143143
input+=("${BASH_REMATCH[1]}")
144144
input+=("${BASH_REMATCH[2]}")
145-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
145+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
146146
input+=("${BASH_REMATCH[1]}")
147147
input+=("${BASH_REMATCH[2]}")
148-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
148+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
149149
flags="${BASH_REMATCH[1]}"
150150
for (( i=0 ; i < ${#flags} ; i++ )); do
151151
input+=("-${flags:i:1}")
@@ -157,7 +157,6 @@ normalize_input() {
157157
shift
158158
done
159159
}
160-
161160
# :command.inspect_args
162161
inspect_args() {
163162
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/catch-all/download

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ normalize_input() {
5858

5959
while [[ $# -gt 0 ]]; do
6060
arg="$1"
61-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
61+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
6262
input+=("${BASH_REMATCH[1]}")
6363
input+=("${BASH_REMATCH[2]}")
64-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
64+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
6565
input+=("${BASH_REMATCH[1]}")
6666
input+=("${BASH_REMATCH[2]}")
67-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
67+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
6868
flags="${BASH_REMATCH[1]}"
6969
for (( i=0 ; i < ${#flags} ; i++ )); do
7070
input+=("-${flags:i:1}")
@@ -76,7 +76,6 @@ normalize_input() {
7676
shift
7777
done
7878
}
79-
8079
# :command.inspect_args
8180
inspect_args() {
8281
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/colors/colorly

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ normalize_input() {
6363

6464
while [[ $# -gt 0 ]]; do
6565
arg="$1"
66-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
66+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
6767
input+=("${BASH_REMATCH[1]}")
6868
input+=("${BASH_REMATCH[2]}")
69-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
69+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
7070
input+=("${BASH_REMATCH[1]}")
7171
input+=("${BASH_REMATCH[2]}")
72-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
72+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
7373
flags="${BASH_REMATCH[1]}"
7474
for (( i=0 ; i < ${#flags} ; i++ )); do
7575
input+=("-${flags:i:1}")
@@ -81,7 +81,6 @@ normalize_input() {
8181
shift
8282
done
8383
}
84-
8584
# :command.inspect_args
8685
inspect_args() {
8786
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/command-default/ftp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ normalize_input() {
119119

120120
while [[ $# -gt 0 ]]; do
121121
arg="$1"
122-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
122+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
123123
input+=("${BASH_REMATCH[1]}")
124124
input+=("${BASH_REMATCH[2]}")
125-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
125+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
126126
input+=("${BASH_REMATCH[1]}")
127127
input+=("${BASH_REMATCH[2]}")
128-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
128+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
129129
flags="${BASH_REMATCH[1]}"
130130
for (( i=0 ; i < ${#flags} ; i++ )); do
131131
input+=("-${flags:i:1}")
@@ -137,7 +137,6 @@ normalize_input() {
137137
shift
138138
done
139139
}
140-
141140
# :command.inspect_args
142141
inspect_args() {
143142
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/command-groups/ftp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ normalize_input() {
166166

167167
while [[ $# -gt 0 ]]; do
168168
arg="$1"
169-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
169+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
170170
input+=("${BASH_REMATCH[1]}")
171171
input+=("${BASH_REMATCH[2]}")
172-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
172+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
173173
input+=("${BASH_REMATCH[1]}")
174174
input+=("${BASH_REMATCH[2]}")
175-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
175+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
176176
flags="${BASH_REMATCH[1]}"
177177
for (( i=0 ; i < ${#flags} ; i++ )); do
178178
input+=("-${flags:i:1}")
@@ -184,7 +184,6 @@ normalize_input() {
184184
shift
185185
done
186186
}
187-
188187
# :command.inspect_args
189188
inspect_args() {
190189
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/commands-nested/cli

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ normalize_input() {
249249

250250
while [[ $# -gt 0 ]]; do
251251
arg="$1"
252-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
252+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
253253
input+=("${BASH_REMATCH[1]}")
254254
input+=("${BASH_REMATCH[2]}")
255-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
255+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
256256
input+=("${BASH_REMATCH[1]}")
257257
input+=("${BASH_REMATCH[2]}")
258-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
258+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
259259
flags="${BASH_REMATCH[1]}"
260260
for (( i=0 ; i < ${#flags} ; i++ )); do
261261
input+=("-${flags:i:1}")
@@ -267,7 +267,6 @@ normalize_input() {
267267
shift
268268
done
269269
}
270-
271270
# :command.inspect_args
272271
inspect_args() {
273272
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/commands/cli

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ normalize_input() {
158158

159159
while [[ $# -gt 0 ]]; do
160160
arg="$1"
161-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
161+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
162162
input+=("${BASH_REMATCH[1]}")
163163
input+=("${BASH_REMATCH[2]}")
164-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
164+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
165165
input+=("${BASH_REMATCH[1]}")
166166
input+=("${BASH_REMATCH[2]}")
167-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
167+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
168168
flags="${BASH_REMATCH[1]}"
169169
for (( i=0 ; i < ${#flags} ; i++ )); do
170170
input+=("-${flags:i:1}")
@@ -176,7 +176,6 @@ normalize_input() {
176176
shift
177177
done
178178
}
179-
180179
# :command.inspect_args
181180
inspect_args() {
182181
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/completions/cli

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ normalize_input() {
178178

179179
while [[ $# -gt 0 ]]; do
180180
arg="$1"
181-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
181+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
182182
input+=("${BASH_REMATCH[1]}")
183183
input+=("${BASH_REMATCH[2]}")
184-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
184+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
185185
input+=("${BASH_REMATCH[1]}")
186186
input+=("${BASH_REMATCH[2]}")
187-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
187+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
188188
flags="${BASH_REMATCH[1]}"
189189
for (( i=0 ; i < ${#flags} ; i++ )); do
190190
input+=("-${flags:i:1}")
@@ -196,7 +196,6 @@ normalize_input() {
196196
shift
197197
done
198198
}
199-
200199
# :command.inspect_args
201200
inspect_args() {
202201
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/config-ini/configly

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ normalize_input() {
165165

166166
while [[ $# -gt 0 ]]; do
167167
arg="$1"
168-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
168+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
169169
input+=("${BASH_REMATCH[1]}")
170170
input+=("${BASH_REMATCH[2]}")
171-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
171+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
172172
input+=("${BASH_REMATCH[1]}")
173173
input+=("${BASH_REMATCH[2]}")
174-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
174+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
175175
flags="${BASH_REMATCH[1]}"
176176
for (( i=0 ; i < ${#flags} ; i++ )); do
177177
input+=("-${flags:i:1}")
@@ -183,7 +183,6 @@ normalize_input() {
183183
shift
184184
done
185185
}
186-
187186
# :command.inspect_args
188187
inspect_args() {
189188
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

examples/custom-includes/download

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ normalize_input() {
5959

6060
while [[ $# -gt 0 ]]; do
6161
arg="$1"
62-
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
62+
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
6363
input+=("${BASH_REMATCH[1]}")
6464
input+=("${BASH_REMATCH[2]}")
65-
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
65+
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
6666
input+=("${BASH_REMATCH[1]}")
6767
input+=("${BASH_REMATCH[2]}")
68-
elif [[ $arg =~ ^-([^-]..+)$ ]]; then
68+
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
6969
flags="${BASH_REMATCH[1]}"
7070
for (( i=0 ; i < ${#flags} ; i++ )); do
7171
input+=("-${flags:i:1}")
@@ -77,7 +77,6 @@ normalize_input() {
7777
shift
7878
done
7979
}
80-
8180
# :command.inspect_args
8281
inspect_args() {
8382
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)

0 commit comments

Comments
 (0)