Compare commits
No commits in common. "7604512684aee5cdc3150e788efca5b72c4cb1fb" and "74acf3fa2dc1177faeec4cbe49990f162023a013" have entirely different histories.
7604512684
...
74acf3fa2d
|
@ -41,48 +41,32 @@
|
||||||
;; NIL → NIL
|
;; NIL → NIL
|
||||||
(defun main ()
|
(defun main ()
|
||||||
"Actual invocation of the program. This is what you should set as :toplevel."
|
"Actual invocation of the program. This is what you should set as :toplevel."
|
||||||
(error-print
|
|
||||||
99 ""
|
|
||||||
(multiple-value-bind (opts free) (opts:get-opts)
|
(multiple-value-bind (opts free) (opts:get-opts)
|
||||||
(when-opt opts :help (help))
|
(when-opt opts :help (help))
|
||||||
(let* ((input-file (car free))
|
(let* ((input-stream (pathname (car free))))
|
||||||
(url-base (or (getf opts :url-base) (getf opts :download-dir) "mirror/"))
|
(when (not input-stream)
|
||||||
(download-dir (or (getf opts :download-dir) url-base)))
|
(format *error-output* "No file provided.~%")
|
||||||
(when (not input-file)
|
(help 2))
|
||||||
(error-print 1 "No HTML file provided. Use --help for more information."))
|
|
||||||
(format
|
(format
|
||||||
't
|
't
|
||||||
(mirror-img:mirror-img
|
(mirror-img:mirror-img
|
||||||
(pathname input-file)
|
input-stream
|
||||||
download-dir
|
#p"mirror/")))))
|
||||||
:url-dir url-base))))))
|
|
||||||
|
|
||||||
(opts:define-opts
|
(opts:define-opts
|
||||||
(:name :help
|
(:name :help
|
||||||
:description "print this help text."
|
:description "print this help text."
|
||||||
:short #\h :long "help")
|
:short #\h :long "help")
|
||||||
(:name :url-base
|
(:name :base
|
||||||
:description "path to mirror directory used in URLs"
|
|
||||||
:short #\b :long "base")
|
|
||||||
(:name :download-dir
|
|
||||||
:description "directory for all mirrored files"
|
:description "directory for all mirrored files"
|
||||||
:short #\d :long "downloads"
|
:short #\b :long "base"
|
||||||
:arg-parser
|
:arg-parser (lambda (dir)
|
||||||
(lambda (dir)
|
(car (directory dir)))))
|
||||||
(handler-case
|
|
||||||
(ensure-directories-exist dir)
|
|
||||||
(error (c)
|
|
||||||
(error-print 11 "Could not access or create directory." c))))))
|
|
||||||
|
|
||||||
;; number stream → nil
|
;; number stream → nil
|
||||||
(defun help (&optional (exit-code 0) (stream *standard-output*))
|
(defun help (&optional (exit-code 0) (stream *standard-output*))
|
||||||
"Prints help message and dies."
|
"Prints help message and dies."
|
||||||
(unix-opts:describe :prefix "usage: mirror-img [-h] [-d DIR] [-b BASE] HTML_FILE"
|
(unix-opts:describe :prefix "usage: mirror-img [-h] [-b DIR] HTML_FILE"
|
||||||
:stream stream)
|
:stream stream)
|
||||||
(unix-opts:exit exit-code))
|
(unix-opts:exit exit-code))
|
||||||
|
|
||||||
;; 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)
|
|
||||||
(unix-opts:exit exit-code))
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue