Skip to content

Commit b9c8804

Browse files
committed
clarify :required usage (again!)
Signed-off-by: Sean Corfield <[email protected]>
1 parent e29c3ce commit b9c8804

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Change Log
22

33
* Release 1.1.next in progress (maybe 1.2.next)
4-
* Clarify `:id` and `:required` properties for when long option is omitted.
4+
* Clarify `:id` and `:required` properties for when long option is omitted. Part of this addresses [TCLI-106](https://clojure.atlassian.net/browse/TCLI-106).
55
* Update dependencies to latest versions for testing; add multi-version testing script; drop Clojure 1.8 support.
66

77
* Release 1.1.230 2024-02-19

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ are not ready to migrate to `parse-opts`.
5353
(:gen-class))
5454

5555
(def cli-options
56-
;; An option with a required argument
56+
;; An option with an argument
5757
[["-p" "--port PORT" "Port number"
5858
:default 80
5959
:parse-fn #(Integer/parseInt %)
@@ -134,7 +134,7 @@ For detailed documentation, please see the docstring of `parse-opts`.
134134
;; if the default value's string representation is very ugly
135135
:default-desc "localhost"
136136
:parse-fn #(InetAddress/getByName %)]
137-
;; If no required argument description is given, the option is assumed to
137+
;; If no argument description is given, the option is assumed to
138138
;; be a boolean option defaulting to nil
139139
[nil "--detach" "Detach from controlling process"]
140140
["-v" nil "Verbosity level; may be specified multiple times to increase value"
@@ -150,16 +150,24 @@ For detailed documentation, please see the docstring of `parse-opts`.
150150
;; value(s) and the new parsed value from each option
151151
:update-fn conj]
152152
["-t" nil "Timeout in seconds"
153-
;; Since there is no long option, :id is required...
153+
;; Since there is no long option, we need to specify the name used for
154+
;; the argument to the option...
154155
:id :timeout
155-
;; ...and we require an argument to be provided:
156+
;; ...and we need to specify the description of argument that is required
157+
;; for the option:
156158
:required "TIMEOUT"
157159
;; parse-long was added in Clojure 1.11:
158160
:parse-fn parse-long]
159161
;; A boolean option that can explicitly be set to false
160162
["-d" "--[no-]daemon" "Daemonize the process" :default true]
161163
["-h" "--help"]])
162164

165+
;; The :required specification provides the name shown in the usage summary
166+
;; for the argument that an option expects. It is only needed when the long
167+
;; form specification of the option is not given, only the short form. In
168+
;; addition, :id must be specified to provide the internal keyword name for
169+
;; the option. There is no way to specify that an option itself is mandatory.
170+
163171
;; The :default values are applied first to options. Sometimes you might want
164172
;; to apply default values after parsing is complete, or specifically to
165173
;; compute a default value based on other option values in the map. For those

0 commit comments

Comments
 (0)