Thanks! That does explain it :)

Would be nice to be able to specify that an option "must be specified in
every invocation" though. I think it would lead to better error messages,
e.g. if several "mandatory" options are forgotten, they will be shown at
once. That is a bit of a hassle when doing it yourself.

Haven't looked too hard at the source though, but any chance of
contributing a patch to something like that?

E.g.
[["-p" "--port PORT" "Port number"
  :mandatory true]]

Cheers,
Alf




On 22 January 2014 14:04, guns <s...@sungpae.com> wrote:

> On Wed 22 Jan 2014 at 01:48:22PM +0100, Alf Kristian Støyle wrote:
>
> > From the documentation it seems that specifying the second part of the
> > "long option" should be enough to make an argument required. So this
> > minimal example should also produce errors:
> >
> > (def cli-options-simplified
> >   [["-p" "--port PORT" "Port number"]])
> > ;=> (var user/cli-options-simplified)
> >
> > (:errors (parse-opts [] cli-options-simplified))
> > ;=> nil
> >
> > So what are we misunderstanding? Any pointers would be greatly
> appreciated.
> >
> > Using Clojure 1.5.1 with tools.cli 0.3.1.
>
> Hi Alf,
>
> An option with a required argument (via "--port PORT" or the :required
> entry) only specifies that the option must be followed by an argument
> _if_ it is specified on the command line. For example,
>
>     $ cmd --port
>
> is an error, but simply
>
>     $ cmd
>
> is not.
>
> If you would like require that --port must be specified in every
> invocation, you can assert its existence/value in the options map:
>
>     (let [{:keys [options errors …]} (parse-opts argv cli-options)]
>       …
>       (assert (:port options) "`--port` must be specified")
>       …)
>
> You can, of course, set a :default value for a required option.
>
>     HTH
>     guns
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to