Skip to content

Commit 8cef8ad

Browse files
authored
Prevent false defaults from being removed/ignored (#97)
1 parent d319f1f commit 8cef8ad

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ For breaking changes, check [here](#breaking-changes).
66

77
## Unreleased
88

9-
- Fix #91: keyword options and hyphen options should not mix
9+
- Fix [#96](https://github.com/babashka/cli/issues/96): prevent false defaults from being removed/ignored
10+
- Fix [#91](https://github.com/babashka/cli/issues/91): keyword options and hyphen options should not mix
1011

1112
## v0.8.58 (2024-03-12)
1213

src/babashka/cli.cljc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@
197197
(assoc aliases alias k)))
198198
require (update :require (fnil #(conj % k) #{}))
199199
validate (update :validate assoc k validate)
200-
default (update :exec-args (fn [new-exec-args]
201-
(assoc new-exec-args k (get exec-args k default))))))
200+
(some? default) (update :exec-args
201+
(fn [new-exec-args]
202+
(assoc new-exec-args k (get exec-args k default))))))
202203
{}
203204
spec)))
204205

@@ -560,8 +561,8 @@
560561
(when (:ref columns)
561562
(if ref ref ""))
562563
(when (or (:default-desc columns)
563-
(:default columns))
564-
(str (or default-desc default "")))
564+
(some? (:default columns)))
565+
(str (or default-desc (str default) "")))
565566
(when (:desc columns)
566567
(if desc desc ""))]))
567568
(if (map? spec)

test/babashka/cli_test.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@
203203
:exec-args {:from :edn, :to :json, :paths ["src" "test"]}}
204204
(cli/spec->opts spec nil)))
205205
(is (= (str/trim "
206-
-p, --pretty Pretty-print output.
206+
-p, --pretty false Pretty-print output.
207207
--paths src test Paths of files to transform.
208208
") (str/trim
209209
(cli/format-opts {:spec [[:pretty {:desc "Pretty-print output."
210+
:default false
210211
:alias :p}]
211212
[:paths {:desc "Paths of files to transform."
212213
:coerce []

0 commit comments

Comments
 (0)