Skip to content

Commit bee110f

Browse files
authored
Merge pull request #194 from rheimus/master
Add extra command line arguments
2 parents 02da072 + e7bb3b0 commit bee110f

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ repositories {
1414
jcenter()
1515
}
1616

17+
18+
1719
group = "com.superzanti.serversync"
1820
version = ssversion
1921

@@ -29,7 +31,11 @@ dependencies {
2931
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
3032

3133
implementation fileTree(dir: 'libs', include: '*.jar')
34+
35+
annotationProcessor 'info.picocli:picocli-codegen:4.3.2'
36+
3237
shadow group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5'
38+
shadow group: 'info.picocli', name: 'picocli', version: '4.3.2'
3339
}
3440

3541
application {

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ssversion = 3.5.1
1+
ssversion = 3.6.0
22
ssname = serversync
33
mainclass = 'com.superzanti.serversync.ServerSync'
44
org.gradle.warning.mode=all

src/main/java/com/superzanti/serversync/RefStrings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class RefStrings {
44
public static final String MODID = "com.superzanti.serversync";
55
public static final String NAME = "ServerSync";
6-
public static final String VERSION = "3.5.1";
6+
public static final String VERSION = "3.6.0";
77

88
public static final String ERROR_TOKEN = "<E>";
99
public static final String DELETE_TOKEN = "<D>";

src/main/java/com/superzanti/serversync/ServerSync.java

+36-11
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
import com.superzanti.serversync.gui.GUI_Client_Mock;
66
import com.superzanti.serversync.server.ServerSetup;
77
import com.superzanti.serversync.util.Logger;
8-
import com.superzanti.serversync.util.ProgramArguments;
98
import com.superzanti.serversync.util.enums.EServerMode;
9+
import picocli.CommandLine;
10+
import picocli.CommandLine.*;
1011

1112
import java.util.Locale;
1213
import java.util.MissingResourceException;
1314
import java.util.ResourceBundle;
15+
import java.util.concurrent.Callable;
1416

15-
public class ServerSync {
17+
@Command(name = "ServerSync", mixinStandardHelpOptions = true, version = "3.6.0", description = "A utility for synchronizing a server<->client style game.")
18+
public class ServerSync implements Callable<Integer> {
1619

1720
/* AWT EVENT DISPATCHER THREAD */
1821

@@ -21,23 +24,45 @@ public class ServerSync {
2124
public static EServerMode MODE;
2225

2326
public static GUI_Client clientGUI;
24-
2527
public static ResourceBundle strings;
2628

27-
public static ProgramArguments arguments;
29+
@Option(names = {"-o", "--progress", "progress-only"}, description = "Only show progress indication. Ignored if '-s', '--server' is specified.")
30+
private boolean modeProgressOnly = false;
31+
@Option(names = {"-q", "--quiet", "silent"}, description = "Remove all GUI interaction. Ignored if '-s', '--server' is specified.")
32+
private boolean modeQuiet = false;
33+
@Option(names = {"-s", "--server", "server"}, description = "Run the program in server mode.")
34+
private boolean modeServer = false;
35+
@Option(names = {"-a", "--address"}, description = "The address of the server you wish to connect to.")
36+
private String serverAddress;
37+
@Option(names = {"-p", "--port"}, description = "The port the server is running on.")
38+
private int serverPort = -1;
2839

2940
public static void main(String[] args) {
30-
arguments = new ProgramArguments(args);
41+
int exitCode = new CommandLine(new ServerSync()).execute(args);
42+
if (exitCode != 0) {
43+
System.exit(exitCode);
44+
}
45+
}
3146

32-
if (arguments.isServer) {
47+
@Override
48+
public Integer call() {
49+
if (modeServer) {
3350
runInServerMode();
3451
} else {
3552
runInClientMode();
3653
}
54+
return 0;
3755
}
3856

39-
private static void commonInit() {
57+
private void commonInit() {
4058
Locale locale = SyncConfig.getConfig().LOCALE;
59+
if (serverAddress != null) {
60+
SyncConfig.getConfig().SERVER_IP = serverAddress;
61+
}
62+
if (serverPort > 0) {
63+
SyncConfig.getConfig().SERVER_PORT = serverPort;
64+
}
65+
4166
try {
4267
Logger.log("Loading language file: " + locale);
4368
strings = ResourceBundle.getBundle("assets.serversync.lang.MessagesBundle", locale);
@@ -47,7 +72,7 @@ private static void commonInit() {
4772
}
4873
}
4974

50-
private static void runInServerMode() {
75+
private void runInServerMode() {
5176
ServerSync.MODE = EServerMode.SERVER;
5277
new Logger("server");
5378
Logger.setSystemOutput(true);
@@ -58,17 +83,17 @@ private static void runInServerMode() {
5883
serverThread.start();
5984
}
6085

61-
private static void runInClientMode() {
86+
private void runInClientMode() {
6287
ServerSync.MODE = EServerMode.CLIENT;
6388
new Logger("client");
6489
SyncConfig config = SyncConfig.getConfig();
6590
commonInit();
6691

6792
Thread clientThread;
68-
if (arguments.syncSilent) {
93+
if (modeQuiet) {
6994
clientGUI = new GUI_Client_Mock();
7095
new Thread(new ClientWorker()).start();
71-
} else if (arguments.syncProgressOnly) {
96+
} else if (modeProgressOnly) {
7297
// TODO setup a progress only version of the GUI
7398
clientGUI = new GUI_Client();
7499
clientGUI.setIPAddress(config.SERVER_IP);

src/main/java/com/superzanti/serversync/util/ProgramArguments.java

-20
This file was deleted.

0 commit comments

Comments
 (0)