l3nz / cli-matic

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

Do not dump stack trace on mistyped subcommand #140

Closed l3nz closed 2 years ago

l3nz commented 2 years ago

version

0.4.3-SNAPSHOT

platform

JVM

problem

On a mistyped subcommand, we get a stacktrace - but this is a normal behavior, not an exception:

$ cm ppl dump-zebr -t 1234
** ERROR: **
Unknown sub-command: 'ppl dump-zebr'.

Exception in thread "main" clojure.lang.ExceptionInfo: Unknown subcommand: dump-zebr - in path ["ppl" "dump-zebr"] {}
    at clojure.core$ex_info.invokeStatic(core.clj:4739)
    at clojure.core$ex_info.invoke(core.clj:4739)
    at cli_matic.utils_v2$walk.invokeStatic(utils_v2.cljc:126)
    at cli_matic.utils_v2$walk.invoke(utils_v2.cljc:85)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at orchestra.spec.test$spec_checking_fn$fn__2567.doInvoke(test.clj:123)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at cli_matic.utils_v2$get_most_specific_value.invokeStatic(utils_v2.cljc:247)
    at cli_matic.utils_v2$get_most_specific_value.invoke(utils_v2.cljc:235)
    at cli_matic.help_gen$getGlobalHelperFn.invokeStatic(help_gen.cljc:275)
    at cli_matic.help_gen$getGlobalHelperFn.invoke(help_gen.cljc:273)
    at cli_matic.core$run_cmd.invokeStatic(core.cljc:610)
    at cli_matic.core$run_cmd.invoke(core.cljc:591)
    at ppl$_main.invokeStatic(ppl.clj:238)
    at ppl$_main.doInvoke(ppl.clj:235)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)

expected behavior

It should print:

** ERROR: **
Unknown sub-command: 'ppl dump-zebr'.

NAME:
 ppl - Inspects Paypal and Stripe

USAGE:
 ppl [global-options] command [command options] [arguments...]

VERSION:
 210906.1

COMMANDS:
   view                 View but not subs
   subs                 View subs only

Where subcommands are relevant to the point in the command tree where it failed. It should also print possible candidates - "Did you mean ..."?

l3nz commented 2 years ago

For example, here:

 ./toycalc-nested.clj subc subb
l3nz commented 2 years ago

fixed

l3nz commented 2 years ago

In 0..5.2 we actually display the list of possible options, as originally required.