In the clojure.tools.cli lib you can provide a tuple of [validation-fn msg]
. If validation-fn
was, say, (fn [input] (s/valid? ... ...))
we currently have no way of making the error message dependent on the input, as its a hardcoded string. Would an issue / patch be welcome to extend the second option to a function, so we can have (fn [input] (s/explain ... ...))
there?
This would I think be helpful for not only spec, but also malli, etc
E.g. for malli I would like to do this:
(def cli-options
[["-n" "--number NUM" "A number"
:parse-fn (m/decoder int? mt/string-transformer)
:validate [(fn [input]
(m/validate [:< 100] input))
(fn [input]
(me/humanize (m/explain [:< 100] input)))]]])
Create a Jira if you have permission or else put it on http://ask.clojure.org - I'm not averse to the idea but would need to analyze it in more depth first. I've never much liked that tuple approach.
I do have JIRA permissions, but I posted in on ask first:
Good job you remembered to post it there -- I'd already forgotten 🙂
The other comment on tools.cli :validate reminded me of it
Until I double-checked, I thought it was the other comment!