dnaeon / clingon

Command-line options parser system for Common Lisp
Other
122 stars 7 forks source link

Proposal: running clingon:run and not exit-ing when in a dumb terminal (like Slime) #12

Closed vindarel closed 1 year ago

vindarel commented 1 year ago

We can already test the args parsing with clingon:parse-command-line <cmd> (list "of" "args")).

To run our application we must call clingon:run <cmd>, and this eventually calls uiop:quit. So, if we try this on the Lisp REPL, the Lisp connection is closed.

What about adding a simple heuristic to maybe not close the connection?

I have used this for some scripts: https://github.com/vindarel/termp/blob/master/termp.lisp It simply checks (not (equalp "dumb" (uiop:getenv "TERM"))), and that works for Emacs & Slime.

A global parameter could do, it would already allow to test a bit more our command during development. Something like

CL-USER> (let ((clingon::*quit* nil))
           (clingon:run (cli/command)))

or use a hook? (I didn't explore them)

CL-USER> (push clingon:*no-quit-hook* clingon:post-hooks)
CL-USER> (clingon:run …)
dnaeon commented 1 year ago

Hey @vindarel ,

That's a good idea. Hooks may not work in this case, since they are meant to be executed in order, before and after a command, so they don't control this behaviour.

We could either use TERM as you've suggested, use a separate dont-quit slot, or an optional argument.. Not sure which one is best at the moment, so I'll have to think about it :)

Btw, on a side note -- great work on CIEL!

Was just browsing the code of CIEL and noticed the simpleHTTPserver and thought about mentioning that you could probably implement the same in few lines using jingle :)

vindarel commented 1 year ago

'll have to think about it :)

ACK, glad you consider it.


(side note)

oh, and https://github.com/dnaeon/cl-jingle#directory-browser =>

(jingle:serve-directory *app* "/docs" "~/Documents")

nice, I'll have to study it and maybe re-evaluate Clack-based apps… (my main issue is the lack of doc)

I'll mention this alternative, and I'd love if jingle was available to download as a binary.

great work on CIEL!

Thanks! The newly added scripting thing gives it another dimension.

dnaeon commented 1 year ago

Hey @vindarel ,

Another thought on this one -- thinking about implementing this by relying on *FEATURES*. For Sly that would be :SLYNK and for Slime :SWANK should do the trick.

Any thoughts on this?

Thanks!

dnaeon commented 1 year ago

@vindarel , can you please check #13 and test it out?

Let me know if this fixes things for you.

Thanks!

vindarel commented 1 year ago

Very nice and works well for me, thanks.

by relying on FEATURES

seems obvious in retrospect.

dnaeon commented 1 year ago

Merged, thanks!

vindarel commented 12 months ago

Hello, I am reading a case where they had to find a workaround of this (mis)feature: Clack brings in swank. And indeed, we sometimes want a running swank server to connect from our app.

;; https://github.com/endatabas/endb/blob/1db9522610d59797374fe26d5b07d1b4d72dae4f/src/core.lisp
(defun main ()
  ;; clingon:exit-error has a guard against existing the REPL, but clack brings in swank.
  (let ((*features* (remove :swank *features*))
        (app (endb-command)))
    (clingon:run app)))