feat: add help cli arg and add descriptions

This commit is contained in:
punchready 2021-06-07 01:02:40 +02:00
parent 355698db1b
commit 67be103c42
2 changed files with 17 additions and 17 deletions

View File

@ -29,23 +29,30 @@ import java.util.Map;
*/ */
public class Server { public class Server {
private static PartyConfig partyConfig; private static PartyConfig partyConfig;
private static ScenarioConfig scenarioConfig; private static ScenarioConfig scenarioConfig;
private static CharacterConfig characterConfig; private static CharacterConfig characterConfig;
private static Integer maxLobbies; private static Integer maxLobbies;
public static void main(String[] args) { public static void main(String[] args) {
ServerArgs serverArgs = new ServerArgs(); ServerArgs serverArgs = new ServerArgs();
JCommander jc = JCommander.newBuilder()
.addObject(serverArgs)
.build();
try { try {
JCommander.newBuilder() jc.parse(args);
.addObject(serverArgs)
.build()
.parse(args);
} catch (ParameterException e) { } catch (ParameterException e) {
Logger.error("Invalid parameters: {}", e.getMessage()); Logger.error("Invalid parameters: {}", e.getMessage());
System.exit(1); System.exit(1);
return;
}
if(serverArgs.isHelp()) {
jc.usage();
System.exit(0);
return;
} }
// System.out.println(serverArgs); // System.out.println(serverArgs);

View File

@ -11,18 +11,11 @@ public class ServerArgs {
private boolean help; private boolean help;
/** Defines the log level for the current execution of the Server */ /** Defines the log level for the current execution of the Server */
@Parameter(names = {"-l", "--log-level"}, description = """ @Parameter(names = {"-l", "--log-level"}, description = "Log Level: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug, 5 = Trace")
Log Level
0: None
1: Error
2: Warning
3: Info (default)
4: debug
5: trace""")
private Integer logLevel = 3; private Integer logLevel = 3;
/** Equivalent to logLevel = 5. Maximum log level (trace) for everything */ /** Equivalent to logLevel = 5. Maximum log level (trace) for everything */
@Parameter(names = {"-v", "--verbose"}) @Parameter(names = {"-v", "--verbose"}, description = "Enables all log messages")
private boolean verbose = false; private boolean verbose = false;
/** Port that the server listens on */ /** Port that the server listens on */
@ -42,14 +35,14 @@ public class ServerArgs {
private File scenarioConfigFile; private File scenarioConfigFile;
/** Whether the server only checks the configuration files, and then stops execution */ /** Whether the server only checks the configuration files, and then stops execution */
@Parameter(names = {"-C", "--check-conf", "--check-config"}) @Parameter(names = {"-C", "--check-conf", "--check-config"}, description = "Validates the given config files and exits")
private boolean checkConfig = false; private boolean checkConfig = false;
/** The path to the folder in which replays are saved */ /** The path to the folder in which replays are saved */
@Parameter(names = {"--replay", "-r"}) @Parameter(names = {"--replay", "-r"}, description = "Path for replay files to be saved at")
private String folderPath; private String folderPath;
@Parameter(names = {"--max-lobbies", "-L", "--team25-max-lobbies"} ) @Parameter(names = {"--max-lobbies", "-L", "--team25-max-lobbies"}, description = "Maximum amount of lobbies that can be created")
private int maxLobbies = 8; private int maxLobbies = 8;
/** Whether help is requested */ /** Whether help is requested */