feat: implemented command line argument parsing

This commit is contained in:
Yannik Bretschneider 2021-06-04 18:46:05 +02:00
parent 8b03d958cb
commit d534897a5b
2 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package uulm.teamname.marvelous.server.args;
import com.beust.jcommander.IStringConverter;
import java.io.File;
public class FileConverter implements IStringConverter<File> {
@Override
public File convert(String value) {
return new File(value);
}
}

View File

@ -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 + '\'' +
'}';
}
}