Fix UNIX cli error-handling

… I made a silly, brainless mistake here. :P
This commit is contained in:
Jaidyn Ann 2024-05-31 21:40:05 -05:00
parent e765f14583
commit b0edcf78a4

View File

@ -36,21 +36,22 @@
;; nil → nil
(defun main ()
"Actual invocation of the program. This is what you should set as :toplevel."
(error-print
99 ""
(multiple-value-bind (opts free) (opts:get-opts)
(when-opt opts :help (help))
(let* ((input-stream (choose-input-stream (car free)))
(url-base (or (getf opts :url-base) (getf opts :download-dir) "mirror/"))
(download-dir (or (getf opts :download-dir) url-base)))
(when (not input-stream)
(error-print 1 "No HTML file provided. See --help for more information."))
(format
't
(mirror-img:mirror-img
input-stream
download-dir
:url-dir url-base))))))
(handler-case
(multiple-value-bind (opts free) (opts:get-opts)
(when-opt opts :help (help))
(let* ((input-stream (choose-input-stream (car free)))
(url-base (or (getf opts :url-base) (getf opts :download-dir) "mirror/"))
(download-dir (or (getf opts :download-dir) url-base)))
(when (not input-stream)
(error-print 1 "No HTML file provided. See --help for more information."))
(format
't
(mirror-img:mirror-img
input-stream
download-dir
:url-dir url-base))))
(error (c)
(error-print 99 nil c))))
(opts:define-opts
(:name :help
@ -69,6 +70,10 @@
(error (c)
(error-print 11 "Could not access or create directory." c))))))
;;; Output
;;; ————————————————————————————————————————
;; number stream → nil
(defun help (&optional (exit-code 0) (stream *standard-output*))
"Prints help message and dies."
@ -82,7 +87,7 @@
;; number string condition → nil
(defun error-print (exit-code &optional message condition)
"Print an error-message and exit."
(format *error-output* "~@[~A~%~]~@[~A~%~]" message condition)
(format *error-output* "~@[~A~%~]~@[Error: ~A~%~]" message condition)
(unix-opts:exit exit-code))