55import com .superzanti .serversync .gui .GUI_Client_Mock ;
66import com .superzanti .serversync .server .ServerSetup ;
77import com .superzanti .serversync .util .Logger ;
8- import com .superzanti .serversync .util .ProgramArguments ;
98import com .superzanti .serversync .util .enums .EServerMode ;
9+ import picocli .CommandLine ;
10+ import picocli .CommandLine .*;
1011
1112import java .util .Locale ;
1213import java .util .MissingResourceException ;
1314import 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 );
0 commit comments