Permalink
Browse files

Extract make-summary-parts from summarize

  • Loading branch information...
guns committed Dec 9, 2013
1 parent b5c656c commit 9dc1f3c6cc85f4e284b2bcb9cdb64f28e587e83f
Showing with 14 additions and 12 deletions.
  1. +14 −12 src/main/clojure/clojure/tools/cli.clj
@@ -345,22 +345,24 @@
[m (conj errors (str "Unknown option: " (pr-str opt)))]))
[(default-option-map specs) []] tokens))
+(defn- make-summary-parts [all-boolean? specs]
+ (let [{:keys [short-opt long-opt required default default-desc desc]} specs
+ opt (cond (and short-opt long-opt) (str short-opt ", " long-opt)
+ long-opt (str " " long-opt)
+ short-opt short-opt)
+ [opt dd] (if required
+ [(str opt \space required)
+ (or default-desc (if default (str default) ""))]
+ [opt ""])]
+ (if all-boolean?
+ [opt (or desc "")]
+ [opt dd (or desc "")])))
+
(defn summarize
"Reduce options specs into a options summary for printing at a terminal."
[specs]
(let [all-boolean? (every? (comp not :required) specs)
- parts (map (fn [{:keys [short-opt long-opt required default default-desc desc]}]
- (let [opt (cond (and short-opt long-opt) (str short-opt ", " long-opt)
- long-opt (str " " long-opt)
- short-opt short-opt)
- [opt dd] (if required
- [(str opt \space required)
- (or default-desc (if default (str default) ""))]
- [opt ""])]
- (if all-boolean?
- [opt (or desc "")]
- [opt dd (or desc "")])))
- specs)
+ parts (map (partial make-summary-parts all-boolean?) specs)
cl-fmt (if all-boolean?
"~{ ~vA ~vA~}"
"~{ ~vA ~vA ~vA~}")

0 comments on commit 9dc1f3c

Please sign in to comment.