Permalink
Browse files

Honor TCLI-1

"Do not include keys when no value provided and no :default"
  • Loading branch information...
guns committed Dec 3, 2013
1 parent 6e41349 commit 36498aa50175b8cdb12907c990ae334f8d07f920
Showing with 7 additions and 7 deletions.
  1. +2 −4 src/main/clojure/clojure/tools/cli.clj
  2. +5 −3 src/test/clojure/clojure/tools/cli_test.clj
@@ -229,10 +229,6 @@
:long-opt long-opt
:required req
:desc desc
- :default nil
- :default-desc nil
- :parse-fn nil
- :assoc-fn nil
:validate-fn validate-fn
:validate-msg validate-msg}
(select-keys spec-map spec-keys))))
@@ -264,6 +260,8 @@
The option spec entry `:validate [fn msg]` desugars into the two entries
:validate-fn and :validate-msg.
+ A :default entry will not be included in the compiled spec unless specified.
+
An option spec may also be passed as a map containing the entries above,
in which case that subset of the map is transferred directly to the result
vector.
@@ -182,9 +182,11 @@
#'cli/compile-option-specs)
(deftest test-compile-option-specs
- (testing "returns values for all keys in spec-keys"
- (is (= (set (keys (first (compile-option-specs [["-f" "--foo" "desc"]]))))
- (set @#'cli/spec-keys))))
+ (testing "does not set values for :default unless specified"
+ (is (= (map #(contains? % :default) (compile-option-specs
+ [["-f" "--foo"]
+ ["-b" "--bar=ARG" :default 0]]))
+ [false true])))
(testing "interprets first three string arguments as short-opt, long-opt=required, and desc"
(is (= (map (juxt :short-opt :long-opt :required :desc)
(compile-option-specs [["-a" :id :alpha]

0 comments on commit 36498aa

Please sign in to comment.