package d3rty.AAA_app;

/**
 * Created by Danil on 01.10.2016.
 */

import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class Cli {
    private static final Logger log = Logger.getLogger(Cli.class.getName());
    private String[] args = null;
    private Options options = new Options();

    public Cli(String[] args) {

        this.args = args;

        options.addOption("v", "var", true, "Here you can set parameter");
        options.addOption("login", "login", true, "your login");
        options.addOption("pass", "password", true, "your password");
        options.addOption("res", "resource", true, "requested resource (e.g. 'AB.CD.E')");
        options.addOption("role", "role", true, "your role on this resource (READ/WRITE/EXECUTE)");
        options.addOption("ds", "datestart", true, "date of start using [YYYY-MM-DD]");
        options.addOption("de", "dateend", true, "date of end using [YYYY-MM-DD]");
        options.addOption("vol", "volume", true, "volume");
        options.addOption("h", "help", false, "show help");
    }

    public void parse() {
        CommandLineParser parser = new BasicParser();

        CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);

            if (cmd.hasOption("h"))
                help();

            if (cmd.hasOption("v")) {
                log.log(Level.INFO, "Using cli argument -v=" + cmd.getOptionValue("v"));
                // Whatever you want to do with the setting goes here
            } else {
                log.log(Level.SEVERE, "MIssing v option");
                help();
            }
            if (cmd.hasOption("login")) {
            }

            if (cmd.hasOption("pass")) {
            }

            if (cmd.hasOption("res")) {
            }

            if (cmd.hasOption("role")) {
            }

            if (cmd.hasOption("ds")) {
            }

            if (cmd.hasOption("de")) {
            }

            if (cmd.hasOption("val")) {
            }

        } catch (ParseException e) {
            log.log(Level.SEVERE, "Failed to parse comand line properties", e);
            help();
        }
    }

    private void help() {
        // This prints out some help
        HelpFormatter formater = new HelpFormatter();

        formater.printHelp("Main", options);
        System.exit(0);
    }
}
@@ -1779,17 +1779,9 @@
    %7D
- else %7B%0A 
+%0A
     
@@ -1792,121 +1792,91 @@
     
-   log.log(Level.SEVERE, %22MIssing v option%22);%0A                help();%0A            %7D%0A            if 
+if (cmd.hasOption(%22login%22)) %7B%0A                System.out.println
 (cmd.
-has
+get
 Option
+Value
 (%22lo
@@ -1873,34 +1873,33 @@
 nValue(%22login%22))
- %7B
+;
 %0A            %7D%0A%0A

fix Cli