clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
borkdude 2021-02-25T11:48:17.010300Z

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?

borkdude 2021-02-25T11:48:32.010700Z

This would I think be helpful for not only spec, but also malli, etc

borkdude 2021-02-25T11:53:28.011Z

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)))]]])

seancorfield 2021-02-25T16:37:30.013900Z

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.

borkdude 2021-02-27T19:41:09.047900Z

I do have JIRA permissions, but I posted in on ask first:

seancorfield 2021-02-27T20:41:20.048400Z

Good job you remembered to post it there -- I'd already forgotten 🙂

borkdude 2021-02-27T20:43:44.048600Z

The other comment on tools.cli :validate reminded me of it

seancorfield 2021-02-27T20:52:56.048800Z

Until I double-checked, I thought it was the other comment!