Fork me on GitHub
#clojure-dev
<
2021-02-25
>
borkdude11:02:17

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?

borkdude11:02:32

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

borkdude11:02:28

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

seancorfield16:02:30

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.

borkdude19:02:09

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

seancorfield20:02:20

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

borkdude20:02:44

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

seancorfield20:02:56

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