Skip to content

Commit 28f559d

Browse files
committed
Preserve command order in help, accept functions as cmdspec
1 parent 2796c1f commit 28f559d

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## Added
44

5+
- Allow a command spec to be just a function
6+
57
## Fixed
68

7-
## Changed
9+
- Preserve command order in help text when using a vector
810

911
# 0.4.24 (2024-02-17 / 5a1e316)
1012

@@ -60,4 +62,4 @@ approaching the envisioned scope for this library.
6062

6163
- subcommand handling
6264
- rudimentary flag handling
63-
- help text generation
65+
- help text generation

src/lambdaisland/cli.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@
164164
(var? ?var)
165165
(assoc (meta ?var) :command ?var)
166166

167+
(fn? ?var)
168+
{:command ?var}
169+
167170
(var? (:command ?var))
168171
(merge (meta (:command ?var)) ?var)
169172

170173
:else
171174
?var))
172175

173176
(defn prepare-cmdpairs [commands]
174-
(let [m (if (vector? commands) (apply hash-map commands) commands)]
177+
(let [m (if (vector? commands) (partition 2 commands) commands)]
175178
(map (fn [[k v]]
176179
(let [v (to-cmdspec v)
177180
[[cmd] doc argnames] (parse-arg-names k)]

0 commit comments

Comments
 (0)