blob: 3c266ea4f32870d80e18301cd911794cac0b5c86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
;;;; Command line options.
(in-package :extreload)
(defmacro when-option ((options option) &body body)
"When `option` is present in `options`, run `body`."
`(let ((value (getf ,options ,option)))
(when value
,@body)))
(defun exit-with-error (condition exit-code)
"Print the error associated with `condition` on standard error, then exit
with code `exit-code`."
(format *error-output* "error: ~a~%" condition)
(opts:exit exit-code))
(defun handle-option-error (condition)
"Handle errors related to command line options. Prints the error specified by
`condition` and exits with EX_USAGE."
(exit-with-error condition sysexits:+usage+))
(defun parse-options ()
"Parse command line options."
(multiple-value-bind (options free-args)
(handler-bind
((opts:unknown-option #'handle-option-error)
(opts:missing-arg #'handle-option-error)
(opts:arg-parser-failed #'handle-option-error)
(opts:missing-required-option #'handle-option-error))
(opts:get-opts))
(when-option (options :help)
(opts:describe
:usage-of "extreload"
:args "EXTENSION_ID...")
(opts:exit sysexits:+usage+))
(when-option (options :version)
(format t "~a~%" (asdf:component-version (asdf:find-system :extreload)))
(opts:exit sysexits:+ok+))
(when (null (getf options :socket-url))
(format *error-output* "error: '--socket-url' is required~%")
(opts:exit sysexits:+usage+))
;; Error if no extension IDs were given.
(when (null free-args)
(format *error-output* "error: missing extension IDs~%")
(opts:exit sysexits:+usage+))
(make-config :socket-url (getf options :socket-url)
:reload-current-tab (getf options :reload-current-tab)
:debug-output (getf options :debug)
:extension-ids free-args)))
|