Example usage for org.apache.commons.cli BasicParser BasicParser

List of usage examples for org.apache.commons.cli BasicParser BasicParser

Introduction

In this page you can find the example usage for org.apache.commons.cli BasicParser BasicParser.

Prototype

BasicParser

Source Link

Usage

From source file:mitm.application.djigzo.tools.ProxyManager.java

private void handleCommandline(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = createCommandLineOptions();

    HelpFormatter formatter = new HelpFormatter();

    CommandLine commandLine;/*from   w  w w .  ja  va 2s  .co  m*/

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException e) {
        formatter.printHelp(COMMAND_NAME, options, true);

        throw e;
    }

    if (commandLine.getOptions().length == 0 || commandLine.hasOption("help")) {
        formatter.printHelp(COMMAND_NAME, options, true);

        System.exit(2);
    }

    user = commandLine.getOptionValue("user");

    password = commandLine.getOptionValue("password");

    if (commandLine.hasOption("pwd")) {
        System.err.println("Please enter password: ");
        password = new jline.ConsoleReader().readLine(new Character('*'));
    }

    if (commandLine.hasOption("get")) {
        handleGet();
    }
}

From source file:com.asakusafw.testdriver.tools.runner.BatchTestRunner.java

static BatchTestRunner parseArguments(String[] args) throws ParseException {
    assert args != null;
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(OPTIONS, args);

    String batchId = cmd.getOptionValue(OPT_BATCH_ID.getOpt());
    LOG.debug("Batch ID: {}", batchId); //$NON-NLS-1$

    Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt());
    LOG.debug("Batch arguments: {}", arguments); //$NON-NLS-1$

    Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt());
    LOG.debug("Extra properties: {}", arguments); //$NON-NLS-1$

    return new BatchTestRunner(batchId).withArguments(toMap(arguments)).withProperties(toMap(properties));
}

From source file:mv.Main.java

/**
 * Sets up the command line options and parses the user arguments
 *
 * @param args User input arguments/*from   w w  w  .  jav  a 2 s  . c o m*/
 *
 * @return SetupConfigurator object with all arguments set. Returns null if a parsing error happens
 * @see mv.Main.SetupConfigurator
 */
private static SetupConfigurator optionSelector(String[] args) {

    CommandLine line;
    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    boolean writeLog = false;

    options.addOption("a", "asm", true, "ASM source code file. Can be omitted in interactive mode");
    options.addOption("h", "help", false, "Shows this help");
    options.addOption("i", "in", true, "Program input file");
    options.addOption("m", "mode", true,
            "Execution mode (batch | interactive | visual). Batch is the default mode");
    options.addOption("o", "out", true, "Program output file");
    options.addOption("d", "debug", false, "Prints cpu state to log file. Check status.log");

    try {
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Wrong usage: " + exp.getMessage() + SHOW_CLI_HELP);
        return null;
    }

    if (line.hasOption("h")) {
        showHelp();
        return null;
    }

    if (line.hasOption("d")) {
        writeLog = true;
    }

    if (line.hasOption("m")) {
        String s = line.getOptionValue("m");
        if (s.equalsIgnoreCase(ExecutionMode.BATCH.name())) {
            return setupMode(ExecutionMode.BATCH, line, writeLog);

        } else if (s.equalsIgnoreCase(ExecutionMode.INTERACTIVE.name())) {
            return setupMode(ExecutionMode.INTERACTIVE, line, writeLog);

        } else if (s.equalsIgnoreCase(ExecutionMode.WINDOW.name())) {
            return setupMode(ExecutionMode.WINDOW, line, writeLog);

        } else {
            System.err.println(ERR_BAD_MODE);
            return null;
        }
    } else {
        return setupMode(ExecutionMode.BATCH, line, writeLog);
    }
}

From source file:fr.inria.edelweiss.kgdqp.test.TestDQP.java

public static void main(String[] args) throws EngineException, MalformedURLException {

    Options options = new Options();
    Option bgpOpt = new Option("bgp", "modeBGP", false, "specify the evaluation strategy");
    Option helpOpt = new Option("h", "help", false, "print this message");
    Option centralizeOpt = new Option("c", "centralize", false, "to evualuate in a centralized context");
    Option testCaseOpt = new Option("tc", "testCase", true, "chose the test case ( d, g or p)");
    Option roundOpt = new Option("r", "round", true, "the roound of the test ( 0, 1 ..., n)");

    options.addOption(bgpOpt);//from  www .jav  a 2  s  .  c  om
    options.addOption(helpOpt);
    options.addOption(centralizeOpt);
    options.addOption(testCaseOpt);
    options.addOption(roundOpt);

    String header = "blabla";
    String footer = "\nPlease report any issue to macina@i3s.unice.fr";

    TestDQP test = new TestDQP(false);

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("kgdqp", header, options, footer, true);
            System.exit(0);
        }

        if (cmd.hasOption("bgp")) {
            test = new TestDQP(true);
        }

        if (cmd.hasOption("r")) {
            test.setRound(Integer.parseInt(cmd.getOptionValue("r")));
        }

        if (cmd.hasOption("c")) {
            test.testLocal();
        } else {

            if (cmd.hasOption("tc")) {
                String tetsCase = cmd.getOptionValue("tc");
                test.testDQP(tetsCase);
            }
        }

    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    } catch (IOException ex) {
        LogManager.getLogger(TestDQP.class.getName()).log(Level.ERROR, "", ex);
    }
}

From source file:com.spidasoftware.EclipseFormatter.FormatterTest.java

/**
 * OptionToFormat on a file that does exist
 *///from   w ww . j av a2s .  c om
public void testoptionToFormatJavaAbsolutePathDoesExist() {
    fileName = System.getProperty("user.dir") + File.separator + "javaEclipseFormatterTest13243546.java";

    CommandLine cmd = null;
    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    absolutePathFile = new File(fileName);
    try {
        absolutePathFile.createNewFile();
        options.addOption("b", false, "create a backup file");
        cmd = parser.parse(options, new String[] { fileName });
    } catch (ParseException e) {
        log.error(e, e);
    } catch (IOException e) {
        log.error(e, e);
    }
    String[] args = new String[] { fileName };
    boolean exists = Formatter.optionToFormat(cmd, args);
    assertTrue("Formatter.OptionToFormat on a file that does exist", exists);
}

From source file:ca.twoducks.vor.ossindex.report.Assistant.java

/** Main method. Very simple, does not perform sanity checks on input.
 * /* ww w . ja v  a2s  .c o m*/
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    CommandLineParser parser = new BasicParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(getOptions(), args);
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("assistant", getOptions());
            return;
        }

        // Instantiate assistant
        Assistant assistant = new Assistant();

        // Add default plugins
        assistant.addScanPlugin(ChecksumPlugin.class);
        assistant.addScanPlugin(HtmlDependencyPlugin.class);
        assistant.addScanPlugin(NodeDependencyPlugin.class);
        assistant.addScanPlugin(MavenDependencyPlugin.class);
        assistant.addScanPlugin(GemfileDependencyPlugin.class);

        if (line.hasOption(NO_DEPENDENCIES_OPTION)) {
            assistant.setExportDependencies(false);
        } else {
            assistant.setExportDependencies(true);
        }
        assistant.setIncludeImages(!line.hasOption(NO_IMAGES_OPTION));
        assistant.setIncludeArtifacts(!line.hasOption(NO_ARTIFACTS_OPTION));

        // Determine operation type
        boolean doScan = line.hasOption("scan");
        boolean doMerge = line.hasOption("merge");
        boolean doImport = line.hasOption("import");
        int count = 0;
        if (doScan)
            count++;
        if (doMerge)
            count++;
        if (doImport)
            count++;
        if (count > 1) {
            System.err.println("Only one of 'scan', 'merge', or import may be selected");
            return;
        }

        if (doScan) {
            // Get the output directory
            if (!line.hasOption("D")) {
                System.err.println("An output directory must be specified");
                return;
            }
            File outputDir = new File(line.getOptionValue("D"));
            if (!outputDir.exists())
                outputDir.mkdir();
            if (!outputDir.isDirectory()) {
                System.err.println("Output option is not a directory: " + outputDir);
                return;
            }

            doScan(assistant, line.getOptionValue("scan"), outputDir, line.hasOption(VERBOSE_OUTPUT_OPTION));
            return;
        }

        if (doMerge) {
            // Get the output directory
            if (!line.hasOption("D")) {
                System.err.println("An output directory must be specified");
                return;
            }
            File outputDir = new File(line.getOptionValue("D"));
            if (!outputDir.exists())
                outputDir.mkdir();
            if (!outputDir.isDirectory()) {
                System.err.println("Output option is not a directory: " + outputDir);
                return;
            }

            doMerge(assistant, line.getOptionValues("merge"), outputDir);
            return;
        }

        if (doImport) {
            // Get the output directory
            if (!line.hasOption("D")) {
                System.err.println("An output directory must be specified");
                return;
            }
            File outputDir = new File(line.getOptionValue("D"));
            if (!outputDir.exists())
                outputDir.mkdir();
            if (!outputDir.isDirectory()) {
                System.err.println("Output option is not a directory: " + outputDir);
                return;
            }

            doImport(assistant, line.getOptionValue("import"), outputDir);
            return;
        }
    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    }

    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("assistant", getOptions());
    return;
}

From source file:mitm.application.djigzo.tools.CertManager.java

private void handleCommandline(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = createCommandLineOptions();

    HelpFormatter formatter = new HelpFormatter();

    CommandLine commandLine;//from ww  w .  j  a  va 2 s  .  c  o  m

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException e) {
        formatter.printHelp(COMMAND_NAME, options, true);

        throw e;
    }

    initLogging(commandLine.hasOption(loggingOption.getOpt()));

    soapUser = soapUserOption.getValue();

    soapPassword = soapPasswordOption.getValue();

    keyStorePassword = keyStorePasswordOption.getValue();

    if (commandLine.getOptions().length == 0 || commandLine.hasOption(helpOption.getOpt())) {
        formatter.printHelp(COMMAND_NAME, options, true);

        System.exit(1);

        return;
    }

    if (commandLine.hasOption(importOption.getOpt())) {
        if (commandLine.hasOption(cerOption.getOpt())) {
            importCertificates();
        } else if (commandLine.hasOption(pfxOption.getOpt())) {
            importKeyStore();
        }
    } else if (commandLine.hasOption(syncOption.getOpt())) {
        syncKeyAndCertStore();
    }
}

From source file:de.rrze.idmone.utils.jidgen.cli.IdGenOptions.java

/**
 * Fill the internal variable data by parsing a given
 * array of command line options./*from  w w  w.  ja  va2  s . c  o  m*/
 * 
 * @param args
 *          the String array containing all command line options
 * @return the data collection
 * @throws ParseException
 */
public HashMap<String, String> parse(String[] args) throws ParseException {
    // get a list of all stored option objects to be processed
    // excluding all dummy options
    Collection<IdGenOption> options = new HashSet<IdGenOption>();
    options.addAll(this.getOptions());
    options.removeAll(this.dummyOptions.values());
    Iterator<IdGenOption> iter = options.iterator();

    // init the parser
    BasicParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(this, args);

    // iterate over all possible options
    while (iter.hasNext()) {
        IdGenOption currentOption = iter.next();
        //logger.trace("Processing option \"" + currentOption.getShortOpt() + "\"");

        if (commandLine.hasOption(currentOption.getShortOpt())) {
            // option was specified
            String value = commandLine.getOptionValue(currentOption.getShortOpt());
            if (value != null) {
                // option has a specified value
                this.data.put(currentOption.getShortOpt(), value);
                logger.info(currentOption.getShortOpt() + " = " + value);
            } else if (currentOption.hasArg()) {
                // option does NOT have a specified value
                logger.error(currentOption.getShortOpt() + " "
                        + Messages.getString("IdGenOptions.MISSING_ARGUMENT"));
                System.out.println(this.getHelp(false));
                System.exit(170);
            } else {
                // at least put an entry with an empty string in the data array
                // to mark that the option was specified
                this.data.put(currentOption.getShortOpt(), "");
            }
        } else {
            // option was NOT specified, so use default if available
            if (currentOption.hasDefaultValue()) {
                // has default
                logger.info(currentOption.getShortOpt() + " " + Messages.getString("IdGenOptions.USING_DEFAULT")
                        + " " + currentOption.getDefaultValue());
                this.data.put(currentOption.getShortOpt(), currentOption.getDefaultValue());
            }
        }
    }

    return this.data;
}

From source file:com.boundary.sdk.event.EventCLI.java

protected void handleCommandlandArguments(String[] args) throws ParseException {

    configureCommandLineOptions();/*from w  ww  .ja  v a  2s.  c o  m*/
    CommandLineParser parser = new BasicParser();
    cmd = parser.parse(options, args);
    if (cmd.hasOption(OPTION_HELP)) {
        usage();
    }
}

From source file:info.debatty.spark.knngraphs.eval.AbstractTest.java

/**
 *
 * @param args//from   w w  w .  jav  a2  s  .  c  o m
 * @throws ParseException if the command line arguments cannot be parsed
 */
public final void parseArgs(final String[] args) throws ParseException {
    log("Parse command line arguments...");
    Options options = new Options();
    options.addOption("i", true, "Input (dataset) file");
    options.addOption("o", true, "Output file for writing results of test");
    options.addOption("k", true, "K for building the k-nn graph (10)");
    options.addOption("pi", true, "Partition iterations (10)");
    options.addOption("pm", true, "Number of partitions (medoids) (32)");
    options.addOption("ud", true, "Update depth (2)");
    options.addOption("ss", true, "Fast search: Speedup (10)");
    options.addOption("srj", true, "Fast search : random jumps (2)");
    options.addOption("se", true, "Fast search : expansion (1.2)");
    options.addOption("n", true, "Nodes in initial graph (1000)");
    options.addOption("na", true, "Number of nodes to add (1000)");
    options.addOption("ne", true, "Nodes to add before evaluation (100)");
    options.addOption("mur", true, "Medoids update ratio (0)");
    options.addOption("h", false, "Show help");

    CommandLineParser parser = new BasicParser();
    CommandLine cmdline = parser.parse(options, args);

    if (cmdline.hasOption("h") || !cmdline.hasOption("i")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("...", options);
        System.exit(0);
    }

    // graph update algorithm parameters
    k = Integer.valueOf(cmdline.getOptionValue("k", "10"));
    partitioning_iterations = Integer.valueOf(cmdline.getOptionValue("pi", "10"));
    partitioning_medoids = Integer.valueOf(cmdline.getOptionValue("pm", "32"));
    update_depth = Integer.valueOf(cmdline.getOptionValue("ud", "2"));
    medoids_update_ratio = Double.valueOf(cmdline.getOptionValue("mur", "0.0"));

    // Search parameters
    search_speedup = Integer.valueOf(cmdline.getOptionValue("ss", "10"));
    search_random_jumps = Integer.valueOf(cmdline.getOptionValue("srj", "2"));
    search_expansion = Double.valueOf(cmdline.getOptionValue("se", "1.2"));

    // Test parameters
    dataset_file = cmdline.getOptionValue("i");
    result_file = cmdline.getOptionValue("o", "-");
    n = Integer.valueOf(cmdline.getOptionValue("n", "1000"));
    n_add = Integer.valueOf(cmdline.getOptionValue("na", "1000"));
    n_evaluation = Integer.valueOf(cmdline.getOptionValue("ne", "100"));

}