Skip to content

Commit ee4af7e

Browse files
committed
fix TCLI-100 by always showing defaults
1 parent 3918301 commit ee4af7e

4 files changed

Lines changed: 23 additions & 18 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/.calva/output-window
12
/.clj-kondo/.cache
23
/.cpcache
34
/.lein-failures
45
/.lein-repl-history
56
/.lsp
67
/.nrepl-port
78
/.portal
9+
/.socket-repl-port
810
/cljs-test-runner-out
911
target

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
* Release 1.0.next in progress
4+
* Document `:missing`, `:multi`, and `:post-validation` in the docstrings and in the README.
5+
* In the help summary, display default values for all options that provide them [TCLI-100](https://clojure.atlassian.net/browse/TCLI-100). Previously, only options that had required arguments would have their defaults shown.
6+
37
* Release 1.0.206 2021-02-27
48
* Allow validation to be performed either after parsing (before option processing) -- current default -- or after option processing, via the `:post-validation true` flag [TCLI-98](https://clojure.atlassian.net/browse/TCLI-98).
59
* Allow validation message to be a function (of the invalid argument) in addition to being a plain string [TCLI-97](https://clojure.atlassian.net/browse/TCLI-97).

src/main/clojure/clojure/tools/cli.cljc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,17 @@
501501
opt (cond (and short-opt long-opt) (str short-opt ", " long-opt)
502502
long-opt (str " " long-opt)
503503
short-opt short-opt)
504-
[opt dd] (if required
505-
[(str opt \space required)
506-
(or default-desc
507-
(when (contains? spec :default)
508-
(if (some? default)
509-
(str default)
510-
"nil"))
511-
(when default-fn
512-
"<computed>")
513-
"")]
514-
[opt ""])]
504+
[opt dd] [(if required
505+
(str opt \space required)
506+
opt)
507+
(or default-desc
508+
(when (contains? spec :default)
509+
(if (some? default)
510+
(str default)
511+
"nil"))
512+
(when default-fn
513+
"<computed>")
514+
"")]]
515515
(if show-defaults?
516516
[opt dd (or desc "")]
517517
[opt (or desc "")])))
@@ -541,9 +541,8 @@
541541
your user-supplied :summary-fn option) on the compiled option specs."
542542
[specs]
543543
(if (seq specs)
544-
(let [show-defaults? (some #(and (:required %)
545-
(or (contains? % :default)
546-
(contains? % :default-fn))) specs)
544+
(let [show-defaults? (some #(or (contains? % :default)
545+
(contains? % :default-fn)) specs)
547546
parts (map (partial make-summary-part show-defaults?) specs)
548547
lens (apply map (fn [& cols] (apply max (map count cols))) parts)
549548
lines (format-lines lens parts)]

src/test/clojure/clojure/tools/cli_test.cljc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,16 @@
374374
[" -s, --server HOST example.com Upstream server"
375375
" -p, --port PORT 80 Upstream port number"
376376
" -o PATH Output file"
377-
" -v Verbosity level; may be specified more than once"
377+
" -v 0 Verbosity level; may be specified more than once"
378378
" --ternary t|f|? false A ternary option defaulting to false"
379379
" -d, --[no-]daemon Daemonize the process"
380380
" --help"]))))
381-
(testing "does not print :default column when no defaults will be shown"
381+
(testing "prints :default column even when no default for required flag"
382382
(is (= (summarize (compile-option-specs [["-b" "--boolean" "A boolean option with a hidden default"
383383
:default true]
384384
["-o" "--option ARG" "An option without a default"]]))
385-
(join \newline [" -b, --boolean A boolean option with a hidden default"
386-
" -o, --option ARG An option without a default"]))))
385+
(join \newline [" -b, --boolean true A boolean option with a hidden default"
386+
" -o, --option ARG An option without a default"]))))
387387
(testing "works with no options"
388388
(is (= (summarize (compile-option-specs []))
389389
""))))

0 commit comments

Comments
 (0)