diff options
| author | Teddy Wing | 2021-02-01 23:47:30 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-02-02 00:01:16 +0100 | 
| commit | 1f234bd9525be263ea89037096abf39d136da77a (patch) | |
| tree | 3294a9639122f14879048a14a8dd2e1644ba691b | |
| parent | f5ac089ffb8c55154f751d250f40c5d41add834d (diff) | |
| download | extreload-1f234bd9525be263ea89037096abf39d136da77a.tar.bz2 | |
main: Start command line option parsing
Include the 'unix-opts' library described in
http://lispcookbook.github.io/cl-cookbook/scripting.html#parsing-command-line-arguments
for command line option parsing.
Define the options I need. We want a `--socket-url` option, and a list
of extension IDs as free arguments.
Implement the `-V` version command line argument. Thanks to JJJ
(https://stackoverflow.com/users/1337941/jjj) on Stack Overflow for
describing how to get the version number of an ASDF system:
https://stackoverflow.com/questions/11084339/getting-the-version-of-an-asdf-system/11088022#11088022
Add a new `options.lisp` file where we'll add the option parsing restart
error handling functions required by 'unix-opts'.
| -rw-r--r-- | l/extreload.asd | 2 | ||||
| -rw-r--r-- | l/src/main.lisp | 31 | ||||
| -rw-r--r-- | l/src/option.lisp | 6 | 
3 files changed, 35 insertions, 4 deletions
| diff --git a/l/extreload.asd b/l/extreload.asd index 8a1cfc2..73402fb 100644 --- a/l/extreload.asd +++ b/l/extreload.asd @@ -1,12 +1,14 @@  (asdf:defsystem extreload    :version "0.0.1"    :depends-on (:jsown +                :unix-opts                  :wait-group                  :websocket-driver-client)    :components ((:module "src"                  :serial t                  :components ((:file "package")                               (:file "macro") +                             (:file "option")                               (:file "main"))))    :build-operation "program-op" diff --git a/l/src/main.lisp b/l/src/main.lisp index 47e8eb1..5ea0384 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -4,13 +4,36 @@  (defvar *wg* (wait-group:make-wait-group)) +(opts:define-opts +  (:name :socket-url +         :description "DevTools protocol WebSocket URL" +         :long "socket-url" +         :meta-var "SOCKET_URL") +  (:name :help +         :description "print this help menu" +         :short #\h +         :long "help") +  (:name :version +         :description "show the program version" +         :short #\V +         :long "version")) +  (defun main () -  (with-websocket-connection (*client*) -    (wsd:on :message *client* #'ws-on-message) +  (multiple-value-bind (options free-args) (opts:get-opts) +    ; (when-option (options :help)) +    (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)) +        (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 new file mode 100644 index 0000000..d828230 --- /dev/null +++ b/l/src/option.lisp @@ -0,0 +1,6 @@ +(in-package :extreload) + +(defmacro when-option ((options option) &body body) +  `(let ((value (getf ,options ,option))) +     (when value +       ,@body))) | 
