From 3380e4e3af7a1e5d51d018e616ed990a8556d498 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 27 Feb 2021 15:55:22 +0100 Subject: Hide `websocket-send` debug output behind `--debug` flag Make the config containing command line options a global variable. This makes it easy to find out if the `--debug` flag is on in the `websocket-send` function. Not sure about the global variable, but seems fine for now. --- l/src/main.lisp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'l/src/main.lisp') diff --git a/l/src/main.lisp b/l/src/main.lisp index f6b7d07..9eaa8e3 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -34,23 +34,24 @@ (handler-bind ((error #'(lambda (e) (exit-with-error e sysexits:+unavailable+)))) - (let ((config (parse-options))) - ;; Store the WebSocket client as a global. - (defvar *client* (ws-client config)) + ;; Store the config as a global. + (defvar *config* (parse-options)) - (trivial-timeout:with-timeout (+timeout-seconds+) - (with-websocket-connection (*client*) - (wsd:on :message *client* - #'(lambda (message) - (ws-on-message - message - (extension-ids config) - config))) + (trivial-timeout:with-timeout (+timeout-seconds+) + (with-websocket-connection ((ws-client *config*)) + (wsd:on :message (ws-client *config*) + #'(lambda (message) + (ws-on-message + message + (extension-ids *config*) + *config*))) - (websocket-send *client* (target-get-targets-msg - (next-call-id *devtools-root-call-id*))) + (websocket-send + (ws-client *config*) + (target-get-targets-msg + (next-call-id *devtools-root-call-id*))) - (wait-group:wait *wg*)))))) + (wait-group:wait *wg*))))) (defun ws-on-message (message extension-ids config) (let* ((response (jsown:parse message)) @@ -109,7 +110,7 @@ (defun attach-to-target (extension) (let ((target-id (json-obj-get extension "targetId"))) - (websocket-send *client* + (websocket-send (ws-client *config*) (target-attach-to-target-msg (next-call-id *devtools-root-call-id*) target-id)))) @@ -117,7 +118,7 @@ (defun reload-extension (session-id) (setf *last-session-id* session-id) (websocket-send - *client* + (ws-client *config*) (runtime-evaluate-msg (next-call-id *devtools-secondary-call-id*) session-id @@ -131,7 +132,7 @@ (wait-group:add *wg*) (websocket-send - *client* + (ws-client *config*) (runtime-evaluate-msg (next-call-id *devtools-secondary-call-id*) session-id @@ -145,7 +146,8 @@ (filter #'extensionp targets))) (defun websocket-send (client data) - (format t "Sending: ~a~%" data) + (when (debug-output *config*) + (format t "Sending: ~a~%" data)) (wsd:send client data) (wait-group:add *wg*)) -- cgit v1.2.3