Started work on API and remembrance fuction

This commit is contained in:
2025-02-21 13:31:13 +01:00
parent 9daae9211f
commit da2cb69b1b
11 changed files with 331 additions and 42 deletions

View File

@@ -8,6 +8,7 @@ version = '1.0-SNAPSHOT'
dependencies {
implementation project(":Display")
implementation project(":API")
implementation project(":Core")
}
jar{

View File

@@ -1,23 +1,24 @@
package me.zacharias.chat.launcher;
import me.zacharias.chat.api.APIServer;
import me.zacharias.chat.core.LaunchOptions;
import me.zacharias.chat.display.Display;
public class Launcher {
public static void main(String[] args) {
boolean serverMode = false;
int port = 39075;
String redirectedOutput = null;
LaunchOptions options = LaunchOptions.getInstance();
for (int i = 0; i < args.length; i++) {
String arg = args[i].toLowerCase();
String argValue = (i + 1 < args.length) ? args[i + 1] : null;
switch (arg) {
case "-s", "--server" -> serverMode = true;
case "-s", "--server" -> options.setServerMode(true);
case "-p", "--port" -> {
if (argValue != null) {
port = Integer.parseInt(argValue);
options.setPort(Integer.parseInt(argValue));
i++;
} else {
System.out.println("Missing argument for -p or --port option");
System.exit(1);
@@ -25,7 +26,8 @@ public class Launcher {
}
case "-o", "--output" -> {
if (argValue != null) {
redirectedOutput = argValue;
options.setRedirectOutput(argValue);
i++;
} else {
System.out.println("Missing argument for -o or --output option");
System.exit(1);
@@ -42,10 +44,20 @@ public class Launcher {
-s --server Starts the application as API server
-p --port Provides the port number that the API server shuld use, defaults to 39075
-o --output Redirects the API Server output to another file
-y Auto accepts to prompts, used for a seamless run. Not recomended when running as Display
-l --loadOld Loads the old message history. [Default]
--api Provides API docs
""");
return;
}
case "-y" ->
{
options.setAutoAccept(true);
}
case "-l", "--loadold" ->
{
options.setLoadOld(true);
}
default -> {
System.out.println("Unknown option: " + arg+"\nUse --help for help");
@@ -55,14 +67,14 @@ public class Launcher {
}
}
if (redirectedOutput != null && !serverMode) {
if (options.getRedirectOutput() != null && !options.isServerMode()) {
System.out.println("Cannot run with a redirected output without running in server mode");
return;
}
if (serverMode) {
if (options.isServerMode()) {
System.out.println("Starting in API mode...");
new APIServer(port, redirectedOutput);
new APIServer();
} else {
System.out.println("Starting in Display mode...");
new Display();