From 7f8495b4976153e7506fb4d12ed5bc33c34fb60b Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Fri, 22 Sep 2023 00:44:23 -0700 Subject: [PATCH] Add hostname arg to cli parser (#214) --- .../example/workflow/launch/WorkflowServerLauncher.java | 3 ++- .../org/eclipse/glsp/server/launch/DefaultCLIParser.java | 7 +++++++ .../src/org/eclipse/glsp/server/utils/LaunchUtil.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/launch/WorkflowServerLauncher.java b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/launch/WorkflowServerLauncher.java index 853396d0..5f3a7777 100644 --- a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/launch/WorkflowServerLauncher.java +++ b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/launch/WorkflowServerLauncher.java @@ -36,6 +36,7 @@ public static void main(final String[] args) { ElkLayoutEngine.initialize(new LayeredMetaDataProvider()); int port = parser.parsePort(); + String host = parser.parseHostname(); ServerModule workflowServerModule = new WorkflowServerModule() .configureDiagramModule(new WorkflowDiagramModule()); @@ -43,7 +44,7 @@ public static void main(final String[] args) { ? new WebsocketServerLauncher(workflowServerModule, "/workflow", parser.parseWebsocketLogLevel()) : new SocketGLSPServerLauncher(workflowServerModule); - launcher.start("localhost", port, parser); + launcher.start(host, port, parser); } catch (ParseException ex) { ex.printStackTrace(); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/launch/DefaultCLIParser.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/launch/DefaultCLIParser.java index 64770509..769aa52b 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/launch/DefaultCLIParser.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/launch/DefaultCLIParser.java @@ -27,6 +27,7 @@ public class DefaultCLIParser extends CLIParser { public static final String OPTION_HELP = "help"; public static final String OPTION_PORT = "port"; + public static final String OPTION_HOST_NAME = "host"; public static final String OPTION_CONSOLE_LOG = "consoleLog"; public static final String OPTION_FILE_LOG = "fileLog"; public static final String OPTION_LOG_LEVEL = "logLevel"; @@ -45,6 +46,10 @@ public int parsePort() { return parseIntOption(OPTION_PORT, DefaultOptions.SERVER_PORT, validator); } + public String parseHostname() { + return parseOption(OPTION_HOST_NAME, DefaultOptions.HOST_NAME); + } + public String parseLogDir() { Predicate validator = (logDirArg) -> { File file = new File(logDirArg); @@ -68,6 +73,8 @@ public Level parseLogLevel() { public static Options getDefaultOptions() { Options options = new Options(); options.addOption("h", OPTION_HELP, false, "Display usage information about GLSPServerLauncher"); + options.addOption("n", OPTION_HOST_NAME, true, String.format("Set server host name. [default='%s']", + DefaultOptions.HOST_NAME)); options.addOption("p", OPTION_PORT, true, String.format("Set server port. [default='%s']", DefaultOptions.SERVER_PORT)); options.addOption("c", OPTION_CONSOLE_LOG, true, diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/LaunchUtil.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/LaunchUtil.java index ca7fa01d..fb0540a5 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/LaunchUtil.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/LaunchUtil.java @@ -49,6 +49,7 @@ private LaunchUtil() {} public static final class DefaultOptions { public static final int SERVER_PORT = 0; + public static final String HOST_NAME = "127.0.0.1"; public static final Level LOG_LEVEL = Level.INFO; public static final String LOG_DIR = new File("./logs/").getAbsolutePath(); public static final boolean CONSOLE_LOG_ENABLED = true;