From 376075df8a7b2bf7cd6f1116038325128b3a6d58 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 2 Aug 2018 02:10:22 +0100 Subject: [PATCH] execute a script if provided one --- .../main/groovy/com/muwire/core/Core.groovy | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 8daf3e56..5d159b71 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -109,9 +109,25 @@ class Core { ConnectionEstablisher connector = new ConnectionEstablisher(eventBus, i2pConnector, props, connectionManager, hostCache) connector.start() - // ... at the end, sleep - log.info("initialized everything, sleeping") - Thread.sleep(Integer.MAX_VALUE) + // ... at the end, sleep or execute script + if (args.length == 0) { + log.info("initialized everything, sleeping") + Thread.sleep(Integer.MAX_VALUE) + } else { + log.info("executing script ${args[0]}") + File f = new File(args[0]) + if (!f.exists()) { + log.warning("Script file doesn't exist") + System.exit(1) + } + + def binding = new Binding() + binding.setProperty("eventBus", eventBus) + // TOOD: other bindings? + def shell = new GroovyShell(binding) + def script = shell.parse(f) + script.run() + } } }