From 84e1fac262a0ba43e1bfba1afa412715857bbf83 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Mon, 15 Jan 2024 19:37:25 +0100 Subject: [PATCH] Refactor entry point. (#464) Parse the arguments only in main, and pass on the parsed arguments. --------- Co-authored-by: Kasper Lund --- src/jaguar.toit | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/jaguar.toit b/src/jaguar.toit index 80fd697c..decd269b 100644 --- a/src/jaguar.toit +++ b/src/jaguar.toit @@ -54,13 +54,22 @@ container-done / monitor.Semaphore ::= monitor.Semaphore registry_ / ContainerRegistry ::= ContainerRegistry main arguments: + device := Device.parse arguments + endpoints := [ + EndpointHttp logger, + ] + uart := device.config.get "endpointUart" + if uart: endpoints.add (EndpointUart --config=uart --logger=logger) + main device endpoints + +main device/Device endpoints/List: try: // We try to start all installed containers, but we catch any // exceptions that might occur from that to avoid blocking // the Jaguar functionality in case something is off. catch --trace: run-installed-containers // We are now ready to start Jaguar. - serve arguments + serve device endpoints finally: | is-exception exception | // We shouldn't be able to get here without an exception having // been thrown, but we play it defensively and force an exception @@ -91,14 +100,7 @@ run-installed-containers -> none: semaphore.up blockers.size.repeat: semaphore.down -serve arguments: - device := Device.parse arguments - endpoints := [ - EndpointHttp logger, - ] - if device.config.contains "endpointUart": - endpoints.add (EndpointUart --config=device.config["endpointUart"] --logger=logger) - +serve device endpoints: lambdas := [] for i := 0; i < endpoints.size; i++: endpoint/Endpoint := endpoints[i]