aboutsummaryrefslogtreecommitdiffstats
path: root/l/src/option.lisp
blob: a294325da40182a0127ff335876cb21dc141a7fe (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
(in-package :extreload)

(defmacro when-option ((options option) &body body)
  `(let ((value (getf ,options ,option)))
     (when value
       ,@body)))

(defun handle-option-error (condition)
  (format *error-output* "error: ~a~%" condition)

  (opts:exit 64))

(defun parse-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 64))

    (when-option (options :version)
      (format t "~a~%" (asdf:component-version (asdf:find-system :extreload)))

      (opts:exit 0))

    ; (if ) ;; If no socket URL, error 64

    (make-instance 'config
                   :socket-url (getf options :socket-url)
                   :extension-ids free-args)))