Skip to content

Commit

Permalink
Allow running command on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxopoly committed Nov 19, 2018
1 parent c2b31e6 commit 7caa5e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/github/maxopoly/angelia_cmd/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class Main {

public static void main(String[] args) {
connManager = ActiveConnectionManager.getInstance();
ServerConnection connection = StartUpCommandParser.parse(args, logger);
StartUpCommandParser parser = new StartUpCommandParser();
ServerConnection connection = parser.parse(args, logger);
if (connection == null) {
System.exit(0);
return;
Expand All @@ -26,6 +27,7 @@ public static void main(String[] args) {
cmdHandler = new CommandHandler(logger);
CommandLineReader reader = new CommandLineReader(logger, connManager, connection.getPlayerName(), cmdHandler);
reader.start();
cmdHandler.handle(parser.getCmdToRun(), connection);
}

public static CommandHandler getCommandHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@
public class StartUpCommandParser {

private static Options options;

private String cmdToRun;

static {
options = new Options();
options.addOption("user", true, "Username");
options.addOption("password", true, "Password");
options.addOption("ip", true, "Server IP");
options.addOption("port", true, "Server port");
options.addOption("saveFile", true, "Auth token save file");
options.addOption("cmd", true, "Command to run once client is fully connected");
}

public static ServerConnection parse(String[] args, Logger logger) {
public ServerConnection parse(String[] args, Logger logger) {
CommandLineParser parser = new DefaultParser();
Console c = System.console();
try {
CommandLine cmd = parser.parse(options, args);
File saveFile = null;
if (cmd.hasOption("cmd")) {
cmdToRun = cmd.getOptionValue("cmd");
}
if (cmd.hasOption("saveFile")) {
saveFile = new File(cmd.getOptionValue("saveFile"));
}
Expand Down Expand Up @@ -101,4 +106,8 @@ public static ServerConnection parse(String[] args, Logger logger) {
return null;
}
}

public String getCmdToRun() {
return cmdToRun;
}
}

0 comments on commit 7caa5e2

Please sign in to comment.