package jbossexploit;

import org.apache.commons.cli.*;

public class Cli {

    public static org.apache.commons.cli.CommandLine parseArguments(String[] args) {
        // Set up CLI options

        Option help = new Option("help",  "print this message");
        Option rhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("Target Hostname or IP Address")
                .create("rhost");

        Option rport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Remote JBoss Port")
                .create("rport");

        Option lhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("IP Address of Attacking Machine")
                .create("lhost");

        Option lport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port on which local handler is listening for a reverse TCP shell")
                .create("lport");

        Option srvport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port for local HTTP server")
                .create("srvport");

        Options options = new Options();

        options.addOption(help);
        options.addOption(rhost);
        options.addOption(rport);
        options.addOption(lhost);
        options.addOption(lport);
        options.addOption(srvport);

        CommandLineParser parser = new DefaultParser();
        org.apache.commons.cli.CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);
        } catch (Exception e) {
            System.out.println("Error parsing arguments.");
            System.exit(1);
        }

        // TODO: Print usage if no arguments are called from CLI
        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar JBossExploit.jar -lhost <host> -lport <port> -rhost <host> -rport <port> -srvport <port>",
                    options);
            System.exit(0);
        }

        return cmd;
    }
}

package jbossexploit;

import org.apache.commons.cli.*;

public class Cli {

    public static org.apache.commons.cli.CommandLine parseArguments(String[] args) {
        // Set up CLI options

        Option help = new Option("help",  "Print this message");
        Option rhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("Target Hostname or IP Address")
                .create("rhost");

        Option rport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Remote JBoss Port")
                .create("rport");

        Option lhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("IP Address of Attacking Machine")
                .create("lhost");

        Option lport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port on which local handler is listening for a reverse TCP shell")
                .create("lport");

        Option srvport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port for local HTTP server")
                .create("srvport");

        Options options = new Options();

        options.addOption(help);
        options.addOption(rhost);
        options.addOption(rport);
        options.addOption(lhost);
        options.addOption(lport);
        options.addOption(srvport);

        CommandLineParser parser = new DefaultParser();
        org.apache.commons.cli.CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);
        } catch (Exception e) {
            System.out.println("Error parsing arguments.");
            System.exit(1);
        }

        if (cmd.hasOption("help") || args.length == 0) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar JBossExploit.jar -lhost <host> -lport <port> -rhost <host> -rport <port> -srvport <port>",
                    options);
            System.exit(0);
        }

        return cmd;
    }
}

Print help menu when no args are passed from the CLI