diff --git a/src/main/java/re/alwyn974/minecraft/bot/cli/CLIParser.java b/src/main/java/re/alwyn974/minecraft/bot/cli/CLIParser.java
index 75deab4..264297b 100644
--- a/src/main/java/re/alwyn974/minecraft/bot/cli/CLIParser.java
+++ b/src/main/java/re/alwyn974/minecraft/bot/cli/CLIParser.java
@@ -1,17 +1,19 @@
package re.alwyn974.minecraft.bot.cli;
import org.apache.commons.cli.*;
+import re.alwyn974.minecraft.bot.MinecraftBOT;
/**
* The command line parser
*
* @author Alwyn974
- * @version 1.0.0
- * @since 1.0.0
+ * @version 1.0.9
+ * @since 1.0.9
*/
public class CLIParser {
private static final Options options = new Options();
+ private static CommandLine cmd;
/**
* Parse the command line arguments
@@ -21,13 +23,41 @@ public class CLIParser {
public static void parse(String... args) throws ParseException {
addOptions();
CommandLineParser parser = new DefaultParser();
- parser.parse(options, args);
+ cmd = parser.parse(options, args);
+ ParseResult result = parseResult();
+ if (result.shouldPrintHelp())
+ printHelp();
}
+ /**
+ * Add the options
+ */
private static void addOptions() {
options.addOption("h", "host", true, "Setup the host value (Default=127.0.0.1)");
options.addOption("p", "port", true, "Setup the port value (Default=25565)");
- options.addOption("u", "user", true, "email of the user");
+ options.addOption("u", "user", true, "Email of the user");
+ options.addOption(null, "password", true, "Password of the user");
+ options.addOption("d", "debug", false, "Activate debug");
+ options.addOption("s", "status", false, "Display only the status of the server");
+ options.addOption(null, "help", false, "Show this help page");
+ }
+
+ private static ParseResult parseResult() {
+ ParseResult result = new ParseResult();
+ result.setHost(cmd.hasOption("h") ? cmd.getOptionValue("h") : MinecraftBOT.getHost());
+ result.setPort(Integer.parseInt(cmd.hasOption("p") ? cmd.getOptionValue("p") : MinecraftBOT.getPort()));
+ result.setEmail(cmd.hasOption("u") ? cmd.getOptionValue("u") : MinecraftBOT.getUsername());
+ result.setPassword(cmd.hasOption("password") ? cmd.getOptionValue("password") : MinecraftBOT.getPassword());
+ result.setStatus(cmd.hasOption("s"));
+ result.setDebug(cmd.hasOption("d"));
+ result.setHelp(cmd.hasOption("help"));
+ return result;
+ }
+
+ public static void printHelp() {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(MinecraftBOT.getProjectName(), options);
+ System.exit(0);
}
}
diff --git a/src/main/java/re/alwyn974/minecraft/bot/cli/ParseResult.java b/src/main/java/re/alwyn974/minecraft/bot/cli/ParseResult.java
new file mode 100644
index 0000000..f6a7f1f
--- /dev/null
+++ b/src/main/java/re/alwyn974/minecraft/bot/cli/ParseResult.java
@@ -0,0 +1,158 @@
+package re.alwyn974.minecraft.bot.cli;
+
+/**
+ * The resulf of parsed args
+ *
+ * @author Alwyn974
+ * @version 1.0.9
+ * @since 1.0.9
+ */
+public class ParseResult {
+
+ private String host;
+ private Integer port;
+ private String email;
+ private String password;
+ private Boolean debug;
+ private Boolean status;
+ private Boolean help;
+
+ /**
+ * Get the host
+ *
+ * @return the host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Set the host
+ *
+ * @param host the host
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ /**
+ * Get the port
+ *
+ * @return the port
+ */
+ public Integer getPort() {
+ return port;
+ }
+
+ /**
+ * Set the port
+ *
+ * @param port the port
+ */
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ /**
+ * Get the email
+ *
+ * @return the email
+ */
+ public String getEmail() {
+ return email;
+ }
+
+ /**
+ * Set the email
+ *
+ * @param email the email
+ */
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ /**
+ * Get the password
+ *
+ * @return the password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Set the password
+ *
+ * @param password the password
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Get if debug is activate
+ *
+ * @return debug value
+ */
+ public Boolean isDebug() {
+ return debug;
+ }
+
+ /**
+ * Set debug
+ *
+ * @param debug debug value
+ */
+ public void setDebug(Boolean debug) {
+ this.debug = debug;
+ }
+
+ /**
+ * Get if status is activate
+ *
+ * @return status value
+ */
+ public Boolean shouldPrintStatus() {
+ return status;
+ }
+
+ /**
+ * The status value
+ *
+ * @param status status value
+ */
+ public void setStatus(Boolean status) {
+ this.status = status;
+ }
+
+ /**
+ * Get if help is activate
+ *
+ * @return help value
+ */
+ public Boolean shouldPrintHelp() {
+ return help;
+ }
+
+ /**
+ * Set help value
+ *
+ * @param help help value
+ */
+ public void setHelp(Boolean help) {
+ this.help = help;
+ }
+
+ @Override
+ public String toString() {
+ return "ParseResult{" +
+ "host='" + host + '\'' +
+ ", port=" + port +
+ ", email='" + email + '\'' +
+ ", password='" + password + '\'' +
+ ", debug=" + debug +
+ ", status=" + status +
+ ", help=" + help +
+ '}';
+ }
+}
diff --git a/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java b/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java
index fac8b8e..c07e82c 100644
--- a/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java
+++ b/src/main/java/re/alwyn974/minecraft/bot/gui/MCBOTPanel.java
@@ -45,7 +45,7 @@ public class MCBOTPanel extends JPanel implements ActionListener {
private final JTextField usernameField = new JTextField(MinecraftBOT.getUsername());
private final JPasswordField passwordField = new JPasswordField(MinecraftBOT.getPassword());
- private final JTextField hostField = new JTextField( MinecraftBOT.getHost());
+ private final JTextField hostField = new JTextField(MinecraftBOT.getHost());
private final JTextField portField = new JTextField(MinecraftBOT.getPort());
private final JTextField outputField = new JTextField();