l3nz / cli-matic

Compact, hands-free [sub]command line parsing library for Clojure.
Eclipse Public License 2.0
361 stars 29 forks source link

Using unknown :type returns unhelpful error #67

Closed WhittlesJr closed 5 years ago

WhittlesJr commented 5 years ago

You get

Exception in thread "main" java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to clojure.lang.IPersistentMap

if you fat finger your :type.

This line should probably throw instead of returning the keyword :unknown: https://github.com/l3nz/cli-matic/blob/7ebd45d3d436f800dab51784bdd937a141812d38/src/cli_matic/utils.cljc#L125

l3nz commented 5 years ago

Makes sense - but can you get me an example of how to reproduce the issue?

WhittlesJr commented 5 years ago
(cli-matic.core/parse-cmds ["--opt1" ":a" "test"]
                           {:global-opts [{:option "opt1"
                                           :short  "o"
                                           :type   :oops}]
                            :commands    [{:command "test"}]})
l3nz commented 5 years ago

You actually get:

-- Spec failed --------------------

Function arguments

  (...
   {:app ...,
    :global-opts
    [{:option ...,
      :as ...,
      :type :deadzebra,
            ^^^^^^^^^^
      :default ...}],
    :commands ...})

should be one of: :edn, :ednfile, :float, :float-0, :int, :int-0, :json, :jsonfile, :keyword, :slurp, :slurplines, :string, :yaml, :yamlfile, :yyyy-mm-dd

or

should satisfy

  set?

That makes sense, but just to be on the safe side, we throw an error.

l3nz commented 5 years ago

I am not making a release for this fix, but thanks for pointing it out. It will go in next release.