Feat: accept optional client username and forward to ClientApp
Pass host/port and optional username via system properties for the UI. Refs #68
This commit is contained in:
@@ -17,10 +17,13 @@ public final class Main {
|
|||||||
printUsage();
|
printUsage();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "server" -> ServerApp.start(args[1]);
|
case "server" -> ServerApp.start(args[1]);
|
||||||
case "client" -> ClientApp.start(args[1]);
|
case "client" -> {
|
||||||
|
String address = args[1];
|
||||||
|
String username = args.length >= 3 ? args[2] : null;
|
||||||
|
ClientApp.start(address, username);
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
printUsage();
|
printUsage();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@@ -29,12 +32,13 @@ public final class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isValid(String[] args) {
|
private static boolean isValid(String[] args) {
|
||||||
if (args.length != 2) {
|
if (args.length < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return switch (args[0]) {
|
return switch (args[0]) {
|
||||||
case "server", "client" -> true;
|
case "server" -> args.length == 2;
|
||||||
|
case "client" -> args.length == 2 || args.length == 3;
|
||||||
default -> false;
|
default -> false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -45,7 +49,7 @@ public final class Main {
|
|||||||
"""
|
"""
|
||||||
Usage:
|
Usage:
|
||||||
java -jar xyz.jar server <listenPort>
|
java -jar xyz.jar server <listenPort>
|
||||||
java -jar xyz.jar client <serverIp>:<serverPort>
|
java -jar xyz.jar client <serverIp>:<serverPort> [<username>]
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ClientApp {
|
|||||||
* @param arg Address in the format "ip:port".
|
* @param arg Address in the format "ip:port".
|
||||||
* @throws IllegalArgumentException if the address format is invalid.
|
* @throws IllegalArgumentException if the address format is invalid.
|
||||||
*/
|
*/
|
||||||
public static void start(String arg) {
|
public static void start(String arg, String username) {
|
||||||
String[] parts = arg.split(":", 2);
|
String[] parts = arg.split(":", 2);
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
throw new IllegalArgumentException("Address must be in format <ip>:<port>.");
|
throw new IllegalArgumentException("Address must be in format <ip>:<port>.");
|
||||||
@@ -36,6 +36,12 @@ public class ClientApp {
|
|||||||
int port = Integer.parseInt(parts[1]);
|
int port = Integer.parseInt(parts[1]);
|
||||||
|
|
||||||
LOGGER.info("You've selected the client. It will connect port {} at host {}", port, host);
|
LOGGER.info("You've selected the client. It will connect port {} at host {}", port, host);
|
||||||
|
// Pass connection defaults and optional username to the UI via system properties
|
||||||
|
System.setProperty("casono.server.host", host);
|
||||||
|
System.setProperty("casono.server.port", String.valueOf(port));
|
||||||
|
if (username != null && !username.isBlank()) {
|
||||||
|
System.setProperty("casono.username", username);
|
||||||
|
}
|
||||||
Launcher.main(new String[] {});
|
Launcher.main(new String[] {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user