Added -h --help to launcher arguments
Added a detailed README renamed the module `luancher` to `launcher`
This commit is contained in:
17
launcher/build.gradle
Normal file
17
launcher/build.gradle
Normal file
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'me.zacharias'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
dependencies {
|
||||
implementation project(":Display")
|
||||
implementation project(":API")
|
||||
}
|
||||
|
||||
jar{
|
||||
manifest {
|
||||
attributes 'Main-Class': 'me.zacharias.chat.launcher.Launcher'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package me.zacharias.chat.launcher;
|
||||
|
||||
import me.zacharias.chat.api.APIServer;
|
||||
import me.zacharias.chat.display.Display;
|
||||
|
||||
public class Launcher {
|
||||
public static void main(String[] args) {
|
||||
boolean serverMode = false;
|
||||
int port = 39075;
|
||||
String redirectedOutput = null;
|
||||
|
||||
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 "-p", "--port" -> {
|
||||
if (argValue != null) {
|
||||
port = Integer.parseInt(argValue);
|
||||
} else {
|
||||
System.out.println("Missing argument for -p or --port option");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
case "-o", "--output" -> {
|
||||
if (argValue != null) {
|
||||
redirectedOutput = argValue;
|
||||
} else {
|
||||
System.out.println("Missing argument for -o or --output option");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
case "--api" -> {
|
||||
System.out.println("API available at https://server.4zellen.se:3000/Zacharias/chat_thing/wiki/API-Docs");
|
||||
return;
|
||||
}
|
||||
case "--help", "-h" -> {
|
||||
System.out.println("""
|
||||
Launch options for AI_chat
|
||||
-h --help Provides this help message
|
||||
-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
|
||||
--api Provides API docs
|
||||
""");
|
||||
return;
|
||||
}
|
||||
|
||||
default -> {
|
||||
System.out.println("Unknown option: " + arg+"\nUse --help for help");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (redirectedOutput != null && !serverMode) {
|
||||
System.out.println("Cannot run with a redirected output without running in server mode");
|
||||
return;
|
||||
}
|
||||
|
||||
if (serverMode) {
|
||||
System.out.println("Starting in API mode...");
|
||||
new APIServer(port, redirectedOutput);
|
||||
} else {
|
||||
System.out.println("Starting in Display mode...");
|
||||
new Display();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user