10.12., 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 91246161 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

use VadereArgumentParser for vadere-server.jar

parent be7b6ad2
Pipeline #320151 passed with stages
in 140 minutes and 54 seconds
......@@ -9,6 +9,7 @@ import net.sourceforge.argparse4j.internal.HelpScreenException;
import org.vadere.manager.server.AbstractVadereServer;
import org.vadere.manager.server.VadereServer;
import org.vadere.manager.server.VadereSingleClientServer;
import org.vadere.util.io.VadereArgumentParser;
import org.vadere.util.logging.Logger;
import java.net.InetAddress;
......@@ -24,11 +25,11 @@ public class Manager {
public static void main(String[] args) {
Logger.setMainArguments(args);
logger = Logger.getLogger(Manager.class);
ArgumentParser p = createArgumentParser();
VadereArgumentParser p = createArgumentParser();
Namespace ns;
try {
ns = p.parseArgs(args);
ns = p.parseArgsAndProcessInitialOptions(args);
ServerSocket serverSocket = new ServerSocket(ns.getInt("port"), 50, InetAddress.getByName(ns.getString("bind")));
logger.infof("Start Server(%s) with Loglevel: %s", VadereServer.currentVersion.getVersionString(), logger.getLevel().toString());
......@@ -49,32 +50,31 @@ public class Manager {
}
}
private static ArgumentParser createArgumentParser() {
ArgumentParser parser = ArgumentParsers.newArgumentParser("Vadere Server")
.defaultHelp(true)
.description("Runs the VADERE pedestrian simulator as a server.");
private static VadereArgumentParser createArgumentParser() {
VadereArgumentParser vadereArgumentParser = new VadereManagerArgumentParser();
ArgumentParser parser = vadereArgumentParser.getArgumentParser();
addOptionsToParser(parser);
return parser;
return vadereArgumentParser;
}
private static void addOptionsToParser(ArgumentParser parser) {
// no action required call to Logger.setMainArguments(args) already configured Logger.
parser.addArgument("--loglevel")
.required(false)
.type(String.class)
.dest("loglevel")
.choices("OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "ALL")
.setDefault("INFO")
.help("Set Log Level.");
// no action required call to Logger.setMainArguments(args) already configured Logger.
parser.addArgument("--logname")
.required(false)
.type(String.class)
.dest("logname")
.help("Write log to given file.");
// parser.addArgument("--loglevel")
// .required(false)
// .type(String.class)
// .dest("loglevel")
// .choices("OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "ALL")
// .setDefault("INFO")
// .help("Set Log Level.");
//
// // no action required call to Logger.setMainArguments(args) already configured Logger.
// parser.addArgument("--logname")
// .required(false)
// .type(String.class)
// .dest("logname")
// .help("Write log to given file.");
// no action required call to Logger.setMainArguments(args) already configured Logger.
......
package org.vadere.manager;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import org.vadere.manager.server.VadereServer;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.io.VadereArgumentParser;
import org.vadere.util.version.Version;
public class VadereManagerArgumentParser extends VadereArgumentParser {
@Override
public Namespace parseArgsAndProcessInitialOptions(String[] args) throws ArgumentParserException {
if (versionIsRequested(args)) {
System.out.println(String.format("Vadere %s (Commit Hash: %s) [TraCI: %s]",
Version.releaseNumber(),
Version.getVersionControlCommitHash(),
VadereServer.currentVersion.getVersionString()));
System.exit(0);
}
Namespace namespace = argumentParser.parseArgs(args);
String configFile = namespace.getString("configfile");
if (configFile != null) {
VadereConfig.setConfigPath(configFile);
}
return namespace;
}
}
......@@ -52,7 +52,7 @@ public class VadereArgumentParser {
return namespace;
}
private boolean versionIsRequested(String[] args) {
protected boolean versionIsRequested(String[] args) {
boolean versionRequrested = false;
for (String currentArgument : args) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment