From 8e11ddad215279411560838917220301e13148fd Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 3 Feb 2021 00:23:16 +0100 Subject: main: Move option parsing code to new function `parse-options` Make a new function `parse-options` that parses the command line options and returns a `config` object. We'll use that object instead of `options` in `main`. Cleans up the `main` function a bit. Currently, we just print the `config` object to ensure we're storing the proper values. Followed Practical Common Lisp's example to implement `print-object` so we can see the contents of its slots: http://www.gigamonkeys.com/book/practical-a-spam-filter.html#the-heart-of-a-spam-filter Still need to implement error checking for a missing `--socket-url` option. --- l/src/main.lisp | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'l/src/main.lisp') 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 -- cgit v1.2.3