Skip to content

Commit

Permalink
Add hostname arg to cli parser (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
tortmayr authored Sep 22, 2023
1 parent 7311929 commit 7f8495b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ 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());

GLSPServerLauncher launcher = parser.isWebsocket()
? new WebsocketServerLauncher(workflowServerModule, "/workflow", parser.parseWebsocketLogLevel())
: new SocketGLSPServerLauncher(workflowServerModule);

launcher.start("localhost", port, parser);
launcher.start(host, port, parser);

} catch (ParseException ex) {
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<String> validator = (logDirArg) -> {
File file = new File(logDirArg);
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7f8495b

Please sign in to comment.