Skip to content

Commit 4b7d57b

Browse files
committed
clarify :id, :required for missing long option with argument
Signed-off-by: Sean Corfield <[email protected]>
1 parent 4831a7c commit 4b7d57b

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
bin/
2020
obj/
2121
target
22+
.rebel_readline_history

README.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ org.clojure/tools.cli {:mvn/version "1.1.230"}
2828
<version>1.1.230</version>
2929
</dependency>
3030
```
31-
The 0.4.x series of tools.cli supports use with `clj`/`deps.edn` and brings
31+
32+
### Historical Release Notes
33+
34+
Starting with 0.4.x, `tools.cli` supports use with `clj`/`deps.edn` and brings
3235
the legacy API to ClojureScript by switching to `.cljc` files. This means it
3336
requires Clojure(Script) 1.9 or later.
3437

35-
The 0.3.x series of tools.cli features a new flexible API, better adherence
38+
The 0.3.x series of tools.cli introduced a new flexible API, better adherence
3639
to GNU option parsing conventions, and ClojureScript support.
3740

38-
The function `clojure.tools.cli/cli` has been superseded by
41+
The old function `clojure.tools.cli/cli` was superseded by
3942
`clojure.tools.cli/parse-opts`, and should not be used in new programs.
4043

41-
The previous function will remain for the foreseeable future. It has also been
44+
The older function will remain for the foreseeable future. It has also been
4245
adapted to use the new tokenizer, so upgrading is still worthwhile even if you
4346
are not ready to migrate to `parse-opts`.
4447

@@ -146,6 +149,13 @@ For detailed documentation, please see the docstring of `parse-opts`.
146149
;; with :multi true, the :update-fn is passed both the existing parsed
147150
;; value(s) and the new parsed value from each option
148151
:update-fn conj]
152+
["-t" nil "Timeout in seconds"
153+
;; Since there is no long option, :id is required...
154+
:id :timeout
155+
;; ...and we require an argument to be provided:
156+
:required "TIMEOUT"
157+
;; parse-long was added in Clojure 1.11:
158+
:parse-fn parse-long]
149159
;; A boolean option that can explicitly be set to false
150160
["-d" "--[no-]daemon" "Daemonize the process" :default true]
151161
["-h" "--help"]])

doc/parse-opts.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ this into complete documentation for the library, with examples, over time):
2424
By default, options are toggles that default to nil, but the second string
2525
parameter may be used to specify that an option requires an argument.
2626
27-
e.g. [\"-p\" \"--port PORT\"] specifies that --port requires an argument,
27+
e.g. ["-p" "--port PORT"] specifies that --port requires an argument,
2828
of which PORT is a short description.
2929
3030
The :property value pairs are optional and take precedence over the
@@ -38,17 +38,18 @@ this into complete documentation for the library, with examples, over time):
3838
transform a value in different ways, but only one of these
3939
option entries may contain a :default(-fn) entry.
4040
41-
This option is mandatory.
41+
This option is mandatory if no long option is provided.
4242
4343
:short-opt The short format for this option, normally set by the first
44-
positional string parameter: e.g. \"-p\". Must be unique.
44+
positional string parameter: e.g. "-p". Must be unique.
4545
4646
:long-opt The long format for this option, normally set by the second
47-
positional string parameter; e.g. \"--port\". Must be unique.
47+
positional string parameter; e.g. "--port". Must be unique.
4848
4949
:required A description of the required argument for this option if
5050
one is required; normally set in the second positional
51-
string parameter after the long option: \"--port PORT\".
51+
string parameter after the long option: "--port PORT",
52+
which would be equivalent to :required "PORT".
5253
5354
The absence of this entry indicates that the option is a
5455
boolean toggle that is set to true when specified on the
@@ -93,7 +94,7 @@ this into complete documentation for the library, with examples, over time):
9394
If this is a boolean option, parse-fn will receive the value
9495
true. This may be used to invert the logic of this option:
9596
96-
[\"-q\" \"--quiet\"
97+
["-q" "--quiet"
9798
:id :verbose
9899
:default true
99100
:parse-fn not]
@@ -118,16 +119,16 @@ this into complete documentation for the library, with examples, over time):
118119
119120
This may be used to create non-idempotent options where you
120121
only need the current value, like setting a verbosity level by
121-
specifying an option multiple times. (\"-vvv\" -> 3)
122+
specifying an option multiple times. ("-vvv" -> 3)
122123
123-
[\"-v\" \"--verbose\"
124+
["-v" "--verbose"
124125
:default 0
125126
:update-fn inc]
126127
127128
:default is applied first. If you wish to omit the :default
128129
option value, use fnil in your :update-fn as follows:
129130
130-
[\"-v\" \"--verbose\"
131+
["-v" "--verbose"
131132
:update-fn (fnil inc 0)]
132133
133134
With :multi true:
@@ -141,15 +142,15 @@ this into complete documentation for the library, with examples, over time):
141142
value based on the current value and a new value from the
142143
command line. This can sometimes be easier than use :assoc-fn.
143144
144-
[\"-f\" \"--file NAME\"
145+
["-f" "--file NAME"
145146
:default []
146147
:update-fn conj
147148
:multi true]
148149
149150
:default is applied first. If you wish to omit the :default
150151
option value, use fnil in your :update-fn as follows:
151152
152-
[\"-f\" \"--file NAME\"
153+
["-f" "--file NAME"
153154
:update-fn (fnil conj [])
154155
:multi true]
155156

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@
438438
transform a value in different ways, but only one of these
439439
option entries may contain a :default(-fn) entry.
440440
441-
This option is mandatory.
441+
This option is mandatory if no long option is provided.
442442
443443
:short-opt The short format for this option, normally set by the first
444444
positional string parameter: e.g. \"-p\". Must be unique.
@@ -448,7 +448,8 @@
448448
449449
:required A description of the required argument for this option if
450450
one is required; normally set in the second positional
451-
string parameter after the long option: \"--port PORT\".
451+
string parameter after the long option: \"--port PORT\",
452+
which would be equivalent to :required \"PORT\".
452453
453454
The absence of this entry indicates that the option is a
454455
boolean toggle that is set to true when specified on the

0 commit comments

Comments
 (0)