|
227 | 227 | (try
|
228 | 228 | [(parse-fn value) nil]
|
229 | 229 | (catch Error e
|
230 |
| - [nil (parse-error opt optarg (str e))])) |
| 230 | + [nil (parse-error opt optarg (ex-message e))])) |
231 | 231 | [value nil])]
|
232 | 232 | (if error
|
233 | 233 | [::error error]
|
|
269 | 269 | default-fns (default-option-map specs :default-fn)
|
270 | 270 | requireds (missing-errors specs)]
|
271 | 271 | (-> (reduce
|
272 |
| - (fn [[m ids errors] [opt-type opt optarg]] |
273 |
| - (if-let [spec (find-spec specs opt-type opt)] |
274 |
| - (let [[value error] (parse-optarg spec opt optarg) |
275 |
| - id (:id spec)] |
276 |
| - (if-not (= value ::error) |
277 |
| - (if (and strict |
278 |
| - (or (find-spec specs :short-opt optarg) |
279 |
| - (find-spec specs :long-opt optarg))) |
280 |
| - [m ids (conj errors (missing-required-error opt (:required spec)))] |
281 |
| - [(if-let [update-fn (:update-fn spec)] |
282 |
| - (update-in m [id] update-fn) |
283 |
| - ((:assoc-fn spec assoc) m id value)) |
284 |
| - (conj ids id) |
285 |
| - errors]) |
286 |
| - [m ids (conj errors error)])) |
287 |
| - [m ids (conj errors (str "Unknown option: " (pr-str opt)))])) |
288 |
| - [defaults [] []] tokens) |
| 272 | + (fn [[m ids errors] [opt-type opt optarg]] |
| 273 | + (if-let [spec (find-spec specs opt-type opt)] |
| 274 | + (let [[value error] (parse-optarg spec opt optarg) |
| 275 | + id (:id spec)] |
| 276 | + (if-not (= value ::error) |
| 277 | + (if (and strict |
| 278 | + (or (find-spec specs :short-opt optarg) |
| 279 | + (find-spec specs :long-opt optarg))) |
| 280 | + [m ids (conj errors (missing-required-error opt (:required spec)))] |
| 281 | + [(if-let [update-fn (:update-fn spec)] |
| 282 | + (update-in m [id] update-fn) |
| 283 | + ((:assoc-fn spec assoc) m id value)) |
| 284 | + (conj ids id) |
| 285 | + errors]) |
| 286 | + [m ids (conj errors error)])) |
| 287 | + [m ids (conj errors (str "Unknown option: " (pr-str opt)))])) |
| 288 | + [defaults [] []] tokens) |
289 | 289 | (#(reduce
|
290 | 290 | (fn [[m ids errors] [id error]]
|
291 | 291 | (if (contains? m id)
|
|
338 | 338 |
|
339 | 339 | (defn- required-arguments [specs]
|
340 | 340 | (reduce
|
341 |
| - (fn [s {:keys [required short-opt long-opt]}] |
342 |
| - (if required |
343 |
| - (into s (remove nil? [short-opt long-opt])) |
344 |
| - s)) |
345 |
| - #{} specs)) |
| 341 | + (fn [s {:keys [required short-opt long-opt]}] |
| 342 | + (if required |
| 343 | + (into s (remove nil? [short-opt long-opt])) |
| 344 | + s)) |
| 345 | + #{} specs)) |
346 | 346 |
|
347 | 347 | (defn ^{:added "1.0"} summarize
|
348 | 348 | "Reduce options specs into a options summary for printing at a terminal.
|
|
367 | 367 | As of 0.4.1, this also applies any :default-fn present."
|
368 | 368 | [option-specs]
|
369 | 369 | (let [specs (compile-option-specs option-specs)
|
370 |
| - vals (default-option-map specs :default)] |
| 370 | + vals (default-option-map specs :default)] |
371 | 371 | (reduce (fn [m [id f]]
|
372 | 372 | (if (contains? m id)
|
373 | 373 | m
|
|
0 commit comments