diff options
-rw-r--r-- | l/extreload.asd | 2 | ||||
-rw-r--r-- | l/src/config.lisp | 6 | ||||
-rw-r--r-- | l/src/main.lisp | 33 | ||||
-rw-r--r-- | l/src/option.lisp | 28 |
4 files changed, 42 insertions, 27 deletions
diff --git a/l/extreload.asd b/l/extreload.asd index 9a09c1b..0dd04ed 100644 --- a/l/extreload.asd +++ b/l/extreload.asd @@ -8,8 +8,8 @@ :serial t :components ((:file "package") (:file "macro") - (:file "option") (:file "config") + (:file "option") (:file "main")))) :build-operation "program-op" diff --git a/l/src/config.lisp b/l/src/config.lisp index 86b77d3..6b31dac 100644 --- a/l/src/config.lisp +++ b/l/src/config.lisp @@ -14,3 +14,9 @@ :initform nil :reader reload-current-tab :documentation "True if the current tab should be reloaded"))) + +(defmethod print-object ((object config) stream) + (print-unreadable-object (object stream :type t) + (with-slots (socket-url extension-ids reload-current-tab) object + (format stream ":socket-url ~s :extension-ids ~s :reload-current-tab ~s" + socket-url extension-ids reload-current-tab)))) diff --git a/l/src/main.lisp b/l/src/main.lisp index 9701d5f..6e74ab7 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -20,35 +20,16 @@ :long "version")) (defun main () - (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)) + (let ((config (parse-options))) + (format t "~a~%" config)) - (opts:get-opts)) + ;; TODO: error if no `socket-url` + (with-websocket-connection (*client*) + (wsd:on :message *client* #'ws-on-message) - (when-option (options :help) - (opts:describe - :usage-of "extreload" - :args "EXTENSION_ID...") + (websocket-send *client* (target-get-targets-msg 1)) - (opts:exit 64)) - - (when-option (options :version) - (format t "~a~%" (asdf:component-version (asdf:find-system :extreload))) - - (opts:exit 0)) - - (let* ((socket-url (getf options :socket-url)) - (client (wsd:make-client socket-url))) - (with-websocket-connection (*client*) - (wsd:on :message *client* #'ws-on-message) - - (websocket-send *client* (target-get-targets-msg 1)) - - (wait-group:wait *wg*))))) + (wait-group:wait *wg*))) (defun target-get-targets-msg (call-id) (jsown:to-json diff --git a/l/src/option.lisp b/l/src/option.lisp index 11f7f98..a294325 100644 --- a/l/src/option.lisp +++ b/l/src/option.lisp @@ -9,3 +9,31 @@ (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))) |