Closed mzuther closed 3 years ago
Hi @mzuther this is by design - as we have to return an exit code. See https://github.com/l3nz/cli-matic/blob/3e072260e359be51bf6646e219042c319dd9f5f8/src/cli_matic/core.cljc#L591 - the code is written so that you can call run-cmd*
that will do what you want.
@mzuther thanks for your very accurate report. Apprecited it.
Which teaches us exactly one thing: read the source code before you send bug reports. :smile:
You're more than welcome. Although I ended up using something other than cli-matic because (it just didn't fit my use case, a simple command line DSL), I was quite impressed by the simplicity of using cli-matic. So thanks for that, I know I'll use it sometime soon...
version
0.4.3
platform
problem
cli-matic calls
System/exit
on several occasions and thus kills a running REPL.There is not only the problem of having to re-start your REPL whenever you run cli-matic. Everything the session contains is also being killed, such as variables or functions that weren't saved to disk. I don't use REPLs that way, but some people are reported to run REPLs for days and all of their work might be gone within an instant.
repro
lein new toycalc
[cli-matic "0.4.3"]
toproject.clj
src/toycalc/core.clj
in Emacs (you need a working version of Cider, of course)cli-matic/examples/toycalc.clj
tosrc/toycalc/core.clj
and change its name space to(ns toycalc.core
core.clj
(C-c C-k) and use its name space (C-c M-n M-n)(-main "--help")
System/exit
which exits the REPL ("*** Closed on ...")expected behaviour
First of all, the fact that cli-matic calls
System/exit
and its possible consequences should be made very clear early on in the README (and in bold font, too).Then, please add a function
run-cmd-safe
(or some similar name) that does not ever callSystem/exit
. It should throw exceptions for coding errors and return an error code after parsing (zero for valid command line options, non-zero in any other case). Users of cli-matic could then handle exiting of the app themselves.Also, refer to
run-cmd-safe
in the README.Personally, I would also remove
run-cmd
for good. But that might break a lot of code, so it's probably not a good idea.actual behaviour
Every time I call
run-cmd
, my REPL is killed.