Permalink
Browse files

Fix summarize so it works with no options

Summarize was throwing an exception when called with no options.
  • Loading branch information...
1 parent 0f98dd3 commit 6d18215fecb43d88f320cebfef74f8cba0942ef6 @hugoduncan hugoduncan committed with guns Dec 17, 2013
Showing with 7 additions and 2 deletions.
  1. +3 −1 src/main/clojure/clojure/tools/cli.clj
  2. +4 −1 src/test/clojure/clojure/tools/cli_test.clj
@@ -363,6 +363,7 @@
(defn- format-lines [lens parts]
(let [fmt (case (count lens)
+ 0 nil
2 "~{ ~vA ~vA~}"
3 "~{ ~vA ~vA ~vA~}")]
(map #(s/trimr (cl-format nil fmt (interleave lens %))) parts)))
@@ -372,7 +373,8 @@
[specs]
(let [show-defaults? (some #(and (:required %) (:default %)) specs)
parts (map (partial make-summary-parts show-defaults?) specs)
- lens (apply map (fn [& cols] (apply max (map count cols))) parts)
+ lens (when (seq parts)
+ (apply map (fn [& cols] (apply max (map count cols))) parts))
lines (format-lines lens parts)]
(s/join \newline lines)))
@@ -160,7 +160,10 @@
:default true]
["-o" "--option ARG" "An option without a default"]]))
(join \newline [" -b, --boolean A boolean option with a hidden default"
- " -o, --option ARG An option without a default"])))))
+ " -o, --option ARG An option without a default"]))))
+ (testing "works with no options"
+ (is (= (summarize (compile-option-specs []))
+ ""))))
(deftest test-parse-opts
(testing "parses options to :options"

0 comments on commit 6d18215

Please sign in to comment.