Skip to content

Commit 26e1398

Browse files
committed
Move clingon compatibility into dedicated package
1 parent fb491ba commit 26e1398

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

compat/clingon.lisp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(defpackage :kiln/compat/clingon
2+
(:documentation "Kiln/Clingon compatibility.")
3+
(:use :cl)
4+
(:import-from
5+
:kiln/dispatch
6+
:error-exit-code
7+
:print-error-and-backtrace)
8+
(:local-nicknames
9+
(:cli :clingon)))
10+
(in-package :kiln/compat/clingon)
11+
12+
(defmethod error-exit-code ((e clingon:exit-error))
13+
(cli:exit-error-code e))
14+
15+
(defmethod print-error-and-backtrace ((e clingon:exit-error))
16+
(unless (= 0 (cli:exit-error-code e))
17+
(call-next-method)))

dispatch.lisp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
:kiln/hot-reload
77
:kiln/script-cache
88
:with-user-abort)
9-
(:import-from :clingon)
109
(:import-from :cmd)
1110
(:import-from :kiln/user)
1211
(:import-from :uiop)
1312
(:export
1413
:*entry-point*
1514
:dispatch
15+
:error-exit-code
1616
:exec
1717
:invoke-entry-point
1818
:invoke-script
1919
:missing-main
2020
:no-such-package
2121
:no-such-script
22+
:print-error-and-backtrace
2223
:script-error
2324
:script-error.name
2425
:script-package-error
@@ -163,8 +164,6 @@
163164
"If there is an unhandled subprocess error, return with its exit code."
164165
(or (uiop:subprocess-error-code e)
165166
(call-next-method)))
166-
(:method ((e clingon:exit-error))
167-
(clingon:exit-error-code e))
168167
;; See https://tldp.org/LDP/abs/html/exitcodes.html
169168
(:method ((e no-arguments)) +ex-usage+)
170169
(:method ((e no-such-package)) 126) ;command cannot execute
@@ -254,6 +253,17 @@ Default entry point."
254253
(dispatch/shebang script-name script-args)
255254
(dispatch/package script-name script-args))))))))
256255

256+
(defgeneric print-error-and-backtrace (e)
257+
(:documentation "Print an error")
258+
(:method ((e t))
259+
(let* ((c (type-of e)))
260+
(format *error-output* "~&~@(~a~): "
261+
(substitute #\Space #\- (string c))))
262+
(print-error e *error-output*)
263+
(format *error-output* "~&")
264+
(when (backtrace?)
265+
(uiop:print-backtrace :condition e :stream *error-output*))))
266+
257267
(defun invoke-entry-point ()
258268
"Invoke the function set as `*entry-point*' in an appropriate dynamic
259269
environment.
@@ -281,15 +291,7 @@ handlers to give the desired behavior for scripting."
281291
(unless (zerop exit-code)
282292
(kill-other-threads))
283293
;; NB `uiop:quit' implicitly finishes outputs.
284-
(uiop:quit exit-code))
285-
(print-error-and-backtrace (e)
286-
(let* ((c (type-of e)))
287-
(format *error-output* "~&~@(~a~): "
288-
(substitute #\Space #\- (string c))))
289-
(print-error e *error-output*)
290-
(format *error-output* "~&")
291-
(when (backtrace?)
292-
(uiop:print-backtrace :condition e :stream *error-output*))))
294+
(uiop:quit exit-code)))
293295
(handler-bind (#+sbcl ((or style-warning sb-ext:compiler-note) #'muffle-warning)
294296
((or #+sbcl sb-int:broken-pipe end-of-file)
295297
(lambda (e)
@@ -317,9 +319,9 @@ handlers to give the desired behavior for scripting."
317319
(when (repl-on-error?)
318320
(invoke-script "repl")))))
319321
(with-user-abort
320-
(funcall
321-
(catch 'exec
322-
(constantly (funcall *entry-point*))))
322+
(funcall
323+
(catch 'exec
324+
(constantly (funcall *entry-point*))))
323325
(quit (exit-code))))
324326
(user-abort (e)
325327
(when (backtrace?)

0 commit comments

Comments
 (0)