Skip to content
This repository
Browse code

Applying patch from Stuart Sierra for ticket

  • Loading branch information...
commit f9d92395cb788dd08cb144035a9d5fd8706d10b5 1 parent 74ff546
authored August 07, 2012
8  src/main/clojure/clojure/tools/cli.clj
@@ -49,7 +49,11 @@
49 49
 
50 50
 (defn- default-values-for
51 51
   [specs]
52  
-  (into {} (for [s specs] [(s :name) (s :default)])))
  52
+  (reduce (fn [m s]
  53
+            (if (contains? s :default)
  54
+              (assoc m (:name s) (:default s))
  55
+              m))
  56
+          {} specs))
53 57
 
54 58
 (defn- apply-specs
55 59
   [specs args]
@@ -101,8 +105,8 @@
101 105
             :aliases  (set aliases)
102 106
             :name     (keyword (last aliases))
103 107
             :parse-fn identity
104  
-            :default  (if flag false nil)
105 108
             :flag     flag}
  109
+           (when flag {:default false})
106 110
            options)))
107 111
 
108 112
 (defn cli
8  src/test/clojure/clojure/tools/cli_test.clj
@@ -34,7 +34,13 @@
34 34
     (deftest should-override-when-supplied
35 35
       (is (= {:server "127.0.0.1"}
36 36
              (first (cli ["--server" "127.0.0.1"]
37  
-                         ["--server" :default "10.0.1.10"]))))))
  37
+                         ["--server" :default "10.0.1.10"])))))
  38
+    (deftest should-omit-key-when-no-default
  39
+      (is (= false
  40
+             (contains? (cli ["--server" "127.0.0.1"]
  41
+                             ["--server" :default "10.0.1.10"]
  42
+                             ["--names"])
  43
+                        :server)))))
38 44
 
39 45
   (deftest should-apply-parse-fn
40 46
     (is (= {:names ["john" "jeff" "steve"]}

0 notes on commit f9d9239

Please sign in to comment.
Something went wrong with that request. Please try again.