|
233 | 233 | {:args new-args
|
234 | 234 | :args->opts args->opts})))
|
235 | 235 |
|
236 |
| -(defn- parse-key [arg mode current-opt coerce-opt added] |
| 236 | +(defn- parse-key [arg mode current-opt coerce-opt added known-keys alias-keys] |
237 | 237 | (let [fst-char (first-char arg)
|
238 | 238 | snd-char (second-char arg)
|
239 | 239 | hyphen-opt? (and (not= :keywords mode)
|
240 |
| - (= fst-char \-) |
241 |
| - (not (number-char? snd-char))) |
| 240 | + (= \- fst-char) |
| 241 | + (let [k (keyword (subs arg 1))] |
| 242 | + (or |
| 243 | + (contains? known-keys k) |
| 244 | + (contains? alias-keys k) |
| 245 | + (not (number-char? snd-char))))) |
242 | 246 | mode (or mode (when hyphen-opt? :hyphens))
|
243 | 247 | fst-colon? (= \: fst-char)
|
244 | 248 | kwd-opt? (and (not= :hyphens mode)
|
245 | 249 | fst-colon?
|
246 | 250 | (or (= :boolean coerce-opt)
|
247 |
| - (or (not current-opt) |
248 |
| - (= added current-opt)))) |
| 251 | + (not current-opt) |
| 252 | + (= added current-opt))) |
249 | 253 | mode (or mode
|
250 | 254 | (when kwd-opt?
|
251 | 255 | :keywords))
|
|
307 | 311 | no-keyword-opts (:no-keyword-opts opts)
|
308 | 312 | restrict (or (:restrict opts)
|
309 | 313 | (:closed opts))
|
310 |
| - known-keys (set (concat (keys (if (map? spec) |
311 |
| - spec (into {} spec))) |
| 314 | + spec-map (if (map? spec) |
| 315 | + spec (into {} spec)) |
| 316 | + alias-keys (set (concat (keys aliases) (map :alias (vals spec-map)))) |
| 317 | + known-keys (set (concat (keys spec-map) |
312 | 318 | (vals aliases)
|
313 | 319 | (keys coerce-opts)))
|
314 | 320 | restrict (if (true? restrict)
|
|
362 | 368 | {:keys [hyphen-opt
|
363 | 369 | composite-opt
|
364 | 370 | kwd-opt
|
365 |
| - mode fst-colon]} (parse-key arg mode current-opt coerce-opt added)] |
| 371 | + mode fst-colon]} (parse-key arg mode current-opt coerce-opt added known-keys alias-keys)] |
366 | 372 | (if (or hyphen-opt
|
367 | 373 | kwd-opt)
|
368 | 374 | (let [long-opt? (str/starts-with? arg "--")
|
|
387 | 393 | k nil mode (cons arg-val (rest args)) a->o)
|
388 | 394 | (let [next-args (next args)
|
389 | 395 | next-arg (first next-args)
|
390 |
| - m (parse-key next-arg mode current-opt coerce-opt added) |
| 396 | + m (parse-key next-arg mode current-opt coerce-opt added known-keys alias-keys) |
391 | 397 | negative? (when-not (contains? known-keys k)
|
392 | 398 | (str/starts-with? (str k) ":no-"))]
|
393 | 399 | (if (or (:hyphen-opt m)
|
|
0 commit comments