babashka / cli

Turn Clojure functions into CLIs!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accept error handler function

jmglov opened this issue · comments

cli/parse-opts currently throws an exception in the following cases:

  • A restricted option is encountered
  • A required option is missing
  • Validation fails for an option
  • Coercion fails for an option

I propose adding an :error-fn that would be called with the same arguments as ex-info instead of throwing an exception:

{:error-fn (fn [msg {:keys [babashka.cli/cause option value value}] (case cause ...))}

The :babashka.cli/cause key would be added to the ex-info map with one of the following values:

  • :restricted
  • :missing-required
  • :validation-failed
  • :coercion-failed