From d534897a5bf32f61e38f07c85e49aadff59f392d Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Fri, 4 Jun 2021 18:46:05 +0200 Subject: [PATCH] feat: implemented command line argument parsing --- .../marvelous/server/args/FileConverter.java | 12 ++ .../marvelous/server/args/ServerArgs.java | 112 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/args/FileConverter.java create mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/args/ServerArgs.java diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/args/FileConverter.java b/Server/src/main/java/uulm/teamname/marvelous/server/args/FileConverter.java new file mode 100644 index 0000000..ff2e546 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/args/FileConverter.java @@ -0,0 +1,12 @@ +package uulm.teamname.marvelous.server.args; + +import com.beust.jcommander.IStringConverter; + +import java.io.File; + +public class FileConverter implements IStringConverter { + @Override + public File convert(String value) { + return new File(value); + } +} diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/args/ServerArgs.java b/Server/src/main/java/uulm/teamname/marvelous/server/args/ServerArgs.java new file mode 100644 index 0000000..cce7d23 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/args/ServerArgs.java @@ -0,0 +1,112 @@ +package uulm.teamname.marvelous.server.args; + +import com.beust.jcommander.Parameter; + +import java.io.File; + +public class ServerArgs { + + /** Whether help is requested */ + @Parameter(names = {"-h", "--help", "-?", "--?", "-H"}, help = true) + private boolean help; + + /** Defines the log level for the current execution of the Server */ + @Parameter(names = {"-l", "--log-level"}, description = """ + Log Level + 0: None + 1: Error + 2: Warning + 3: Info (default) + 4: debug + 5: trace""") + private Integer logLevel = 3; + + /** Equivalent to logLevel = 5. Maximum log level (trace) for everything */ + @Parameter(names = {"-v", "--verbose"}) + private boolean verbose = false; + + /** Port that the server listens on */ + @Parameter(names = {"--port", "-p"}, description = "Port the server listens at") + private int port = 1218; + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.PartyConfig PartyConfig} */ + @Parameter(names = {"--conf-match", "-m", "--match-config"}, required = true) + private File matchConfigFile; + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.CharacterConfig CharacterConfig} */ + @Parameter(names = {"--conf-chars", "-c", "--character-config"}, required = true) + private File characterConfigFile; + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig ScenarioConfig} */ + @Parameter(names = {"--conf-scenario", "-s", "--scenario-config"}, required = true) + private File scenarioConfigFile; + + /** Whether the server only checks the configuration files, and then stops execution */ + @Parameter(names = {"--check-conf", "--check-config"}) + private boolean checkConfig = false; + + /** The path to the folder in which replays are saved */ + @Parameter(names = {"--replay", "-r"}) + private String folderPath; + + /** Whether help is requested */ + public boolean isHelp() { + return help; + } + + /** Defines the log level for the current execution of the Server */ + public Integer getLogLevel() { + return logLevel; + } + + /** Equivalent to logLevel = 5. Maximum log level (trace) for everything */ + public boolean isVerbose() { + return verbose; + } + + /** Port that the server listens on */ + public int getPort() { + return port; + } + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.PartyConfig PartyConfig} */ + public File getMatchConfigFile() { + return matchConfigFile; + } + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.CharacterConfig CharacterConfig} */ + public File getCharacterConfigFile() { + return characterConfigFile; + } + + /** File describing the {@link uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig ScenarioConfig} */ + public File getScenarioConfigFile() { + return scenarioConfigFile; + } + + /** Whether the server only checks the configuration files, and then stops execution */ + public boolean isCheckConfig() { + return checkConfig; + } + + /** The path to the folder in which replays are saved */ + public String getFolderPath() { + return folderPath; + } + + + @Override + public String toString() { + return "ServerArgs{" + + "help=" + help + + ", logLevel=" + logLevel + + ", verbose=" + verbose + + ", port=" + port + + ", matchConfigFile=" + matchConfigFile + + ", characterConfigFile=" + characterConfigFile + + ", scenarioConfigFile=" + scenarioConfigFile + + ", checkConfig=" + checkConfig + + ", folderPath='" + folderPath + '\'' + + '}'; + } +}