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:RealignSAMFile.java

/**
 * Method providing the CLI for the main method, also parsing input parameters etc.
 * @param args//from  www  .  j a  va2 s.com
 * @return
 */

private static RealignSAMFile addCLIInterface(String[] args) {
    Options helpOptions = new Options();
    helpOptions.addOption("h", "help", false, "show this help page");
    Options options = new Options();
    options.addOption("h", "help", false, "show this help page");
    options.addOption(OptionBuilder.withLongOpt("input").withArgName("INPUT")
            .withDescription("the input SAM/BAM File").isRequired().hasArg().create("i"));
    options.addOption(OptionBuilder.withLongOpt("reference").withArgName("REFERENCE")
            .withDescription("the unmodified reference genome").isRequired().hasArg().create("r"));
    options.addOption(OptionBuilder.withLongOpt("elongation").withArgName("ELONGATION")
            .withDescription("the elongation factor [INT]").isRequired().hasArg().create("e"));
    options.addOption(OptionBuilder.withLongOpt("filterCircularReads").isRequired(false).withArgName("FILTER")
            .withDescription(
                    "filter the reads that don't map to a circular identifier (true/false), default false")
            .hasArg().create("f"));
    options.addOption(OptionBuilder.withLongOpt("filterNonCircularSequences").isRequired(false)
            .withArgName("FILTERSEQUENCEIDS")
            .withDescription(
                    "filter the sequence identifiers that are not circular identifiers (true/false), default false")
            .hasArg().create("x"));
    HelpFormatter helpformatter = new HelpFormatter();
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(helpOptions, args);
        if (cmd.hasOption('h')) {
            helpformatter.printHelp(CLASS_NAME + "v" + VERSION, options);
            System.exit(0);
        }
    } catch (ParseException e1) {
    }
    String input = "";
    String reference = "";
    String tmpElongation = "";
    Integer elongation = 0;
    String filter = "";
    String filterSequenceIds = "";
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption('i')) {
            input = cmd.getOptionValue('i');
        }
        if (cmd.hasOption('e')) {
            tmpElongation = cmd.getOptionValue('e');
            try {
                elongation = Integer.parseInt(tmpElongation);
            } catch (Exception e) {
                System.err.println("elongation not an Integer: " + tmpElongation);
                System.exit(0);
            }
        }
        if (cmd.hasOption('r')) {
            reference = cmd.getOptionValue('r');
        }
        if (cmd.hasOption('f')) {
            filter = cmd.getOptionValue('f');
            if (filter.equals("true") || filter.equals("TRUE") || filter.equals("1")) {
                filtered = true;
            } else {
                filtered = false;
            }
        }
        if (cmd.hasOption('x')) {
            filterSequenceIds = cmd.getOptionValue('x');
            if (filterSequenceIds.equals("true") || filter.equals("TRUE") || filter.equals("1")) {
                filter_sequence_ids = true;
            } else {
                filter_sequence_ids = false;
            }
        }
    } catch (ParseException e) {
        helpformatter.printHelp(CLASS_NAME, options);
        System.err.println(e.getMessage());
        System.exit(0);
    }

    RealignSAMFile rs = new RealignSAMFile(new File(input), new File(reference), elongation, filter);
    return rs;
}

From source file:com.logicmonitor.ft.jxmtop.JMXTopMain.java

/**
 * @param args : arguments array//from   w  ww.  ja  v a 2 s.c  om
 * @return Run Parameter
 */
private static RunParameter ARGSAnalyser(String[] args) {

    Options options = new Options();
    options.addOption(new Option("h", "help", false, "show this help message"))
            .addOption(new Option("u", true, "User name for remote process"))
            .addOption(new Option("p", true, "Password for remote process"))
            .addOption(new Option("f", true, "Path to the configure file"))
            .addOption(new Option("i", true, "Interval between two scan tasks, unit is second"))
            .addOption(new Option("a", false, "Show alias names instead of jmx paths"));

    CommandLineParser parser = new BasicParser();
    RunParameter runParameter = new RunParameter();
    ArrayList<JMXInPath> inputtedPaths = new ArrayList<JMXInPath>();
    try {
        CommandLine cli = parser.parse(options, args);
        if (args.length == 0 || cli.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("jmxtop jmxURL [jmx path lists]", "To view statuses of jmx paths:", options,
                    "[Use 'Esc' or 'q' or 'Ctrl-c' to exit top console]\n[Use Key UP and Key DOWN to change pages]\n@Support by LogicMonitor",
                    true);
            exit(0);
        }

        runParameter.setValid(true);
        if (cli.hasOption('a')) {
            runParameter.setShowAliasTitle(true);
        }
        if (cli.hasOption('f')) {
            List<JMXInPath> paths_from_file = getPathsFromFile(cli.getOptionValue('f'));
            inputtedPaths.addAll(paths_from_file);
        }

        if (cli.hasOption('u')) {
            runParameter.setUsername(cli.getOptionValue('u'));
        }
        if (cli.hasOption('p')) {
            runParameter.setPassword(cli.getOptionValue('p'));
        }
        if (cli.hasOption('i')) {
            try {
                int interval = Integer.valueOf(cli.getOptionValue('i'));
                if (interval < 0)
                    System.err.println("The interval value is negative! Using default set!");
                else {
                    runParameter.setInterval(interval);
                }
            } catch (Exception e) {
                runParameter.setValid(false);
                runParameter.setValidInfo(
                        runParameter.getValidInfo() + "Argument after <-i> should be an integer\n");
            }
        }
        List<String> others = cli.getArgList();
        boolean jmxurl_found = false;
        for (String other : others) {
            if (other.toLowerCase().startsWith("service:jmx:")) {
                if (jmxurl_found) {
                    runParameter.setValid(false);
                    runParameter.setValidInfo(runParameter.getValidInfo() + "multiple jmxurl found\n");
                    return runParameter;
                } else {
                    jmxurl_found = true;
                    runParameter.setSurl(other.toLowerCase());
                }
            } else {
                inputtedPaths.add(new JMXInPath(other));
            }
        }
        if (!jmxurl_found) {
            runParameter.setValid(false);
            runParameter.setValidInfo(runParameter.getValidInfo()
                    + "No jmxurl found. The jmxurl should start with \"service:jmx:\" \n");
        }
    } catch (ParseException e) {
        e.printStackTrace();
        runParameter.setValid(false);
        runParameter.setValidInfo(runParameter.getValidInfo() + "Exception caught while parse arguments!\n");
    }

    if (inputtedPaths.isEmpty()) {
        runParameter.setValid(false);
        runParameter.setValidInfo(runParameter.getValidInfo() + "No jmx paths inputted");
    } else {
        runParameter.setPaths(inputtedPaths);
    }
    return runParameter;
}

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

/**
 * Test where groovy flag is set true//from  w ww .ja va  2 s  .co  m
 */
public void testgroovyFlagSetTrue() {
    log.info("groovy flag set true");
    Options options = new Options();
    options.addOption("java", false, "only format java files");
    options.addOption("groovy", false, "only format groovy files");
    CommandLine cmd = null;
    CommandLineParser parser = new BasicParser();
    try {
        cmd = parser.parse(options, new String[] { "-groovy" });
    } catch (ParseException e) {
        log.error(e, e);
    }
    assertTrue("groovy flag set true", Formatter.groovyFormatting(cmd) == true);
}

From source file:edu.rice.batchsig.bench.BenchSigner.java

public void parsecmd(String args[]) throws ParseException, InvalidKeyException, NoSuchAlgorithmException,
        InterruptedException, IOException, NoSuchProviderException {
    isVerifying = true;//from w w  w.  jav  a 2  s .  co  m
    commands = new BasicParser().parse(initOptions(), args);
    if (commands.hasOption('h')) {
        (new HelpFormatter()).printHelp("bench", initOptions());
        System.exit(0);
    }

    final int timeout = Integer.parseInt(commands.getOptionValue("timeout", "5000"));
    if (timeout > BIGTIME)
        isBig = true;
    else
        isBig = false;

    if (commands.hasOption("verify")) {
        isTrace = false;
        handleVerifying(timeout);
        return;
    }
    if (commands.hasOption("verifytrace")) {
        isTrace = true;
        handleVerifyTrace(timeout);
        return;
    }

    // Must happen before we create queues.
    isVerifying = false;

    // Figure out if it is a trace before we setup the cipher.
    if (commands.hasOption("signtrace") || commands.hasOption("verifytrace")
            || commands.hasOption("makeverifytrace"))
        isTrace = true;

    // Setup the cipher before we create the queues.
    String signer_id = commands.getOptionValue("signerid", "Host0");

    // Create queues.
    if (commands.hasOption("history")) {
        isBatch = true;
        queuefn = new Function<String, SuspendableProcessQueue<OMessage>>() {
            public SuspendableProcessQueue<OMessage> apply(String signer_id) {
                return new HistoryQueue(setupCipher(signer_id));
            }
        };
    } else if (commands.hasOption("merkle")) {
        isBatch = true;
        queuefn = new Function<String, SuspendableProcessQueue<OMessage>>() {
            public SuspendableProcessQueue<OMessage> apply(String signer_id) {
                return new MerkleQueue(setupCipher(signer_id));
            }
        };
    } else if (commands.hasOption("simple")) {
        isBatch = false;
        queuefn = new Function<String, SuspendableProcessQueue<OMessage>>() {
            public SuspendableProcessQueue<OMessage> apply(String signer_id) {
                return new SimpleQueue(setupCipher(signer_id));
            }
        };
    } else {
        throw new IllegalArgumentException(
                "Unknown signqueue type. Please choose one of -history -merkle or -simple");
    }

    if (commands.hasOption("signtrace")) {
        hotspotSigning();
        handleTraceSigning(timeout);
    } else if (commands.hasOption("sign")) {
        hotspotSigning();
        handleSigning(timeout);
    } else if (commands.hasOption("makeverifytrace")) {
        handleMakeVerifyTrace(0);
    } else {
        throw new Error("Need to use a mode");
    }
}

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

/**
 * Test where groovy flag is set false//from   ww  w.j  a  va2  s . c  o  m
 */
public void testgroovyFlagSetfalse() {
    log.info("groovy flag set false");
    Options options = new Options();
    options.addOption("java", false, "only format java files");
    options.addOption("groovy", false, "only format groovy files");
    CommandLine cmd = null;
    CommandLineParser parser = new BasicParser();
    try {
        cmd = parser.parse(options, new String[] { "-java" });
    } catch (ParseException e) {
        log.error(e, e);
    }
    assertTrue("groovy flag set false", Formatter.groovyFormatting(cmd) == false);
}

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

/**
 * Test where java flag is set true/* ww w .ja  v a  2 s.co m*/
 */
public void testjavaFlagSetTrue() {
    log.info("java flag set true");
    Options options = new Options();
    options.addOption("java", false, "only format java files");
    options.addOption("groovy", false, "only format groovy files");
    CommandLine cmd = null;
    CommandLineParser parser = new BasicParser();
    try {
        cmd = parser.parse(options, new String[] { "-java" });
    } catch (ParseException e) {
        log.error(e, e);
    }
    assertTrue("java flag set true", Formatter.javaFormatting(cmd) == true);
}

From source file:com.ultratechnica.mongodb.Main.java

private static CommandLine parseArgs(String[] args, Options options) {
    CommandLineParser parser = new BasicParser();

    try {// ww w.jav a2  s.  c o  m
        return parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e);

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("java -jar mongodb-benchmark-<version>.jar", "header", options, "footer", true);

        System.exit(1);
    }

    return null;
}

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

private void handleCommandline(String[] args)
        throws IOException, ParseException, WSProxyFactoryException, WebServiceCheckedException {
    CommandLineParser parser = new BasicParser();

    Options options = createCommandLineOptions();

    HelpFormatter formatter = new HelpFormatter();

    CommandLine commandLine;/*from   www.  ja  v a  2s.  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()));

    user = userOption.getValue();

    password = passwordOption.getValue();

    repository = mpaSizeOption.getValue();

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

        System.exit(1);

        return;
    }

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

        return;
    }

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

    if (commandLine.hasOption(mpaSizeOption.getOpt())) {
        retrieveMPAQueueSize();
    }

    if (commandLine.hasOption(crlStoreSizeOption.getOpt())) {
        retrieveCRLStoreSize();
    }

    if (commandLine.hasOption(runningOption.getOpt())) {
        checkRunning();
    }

    if (commandLine.hasOption(mtaSizeOption.getOpt())) {
        retrieveMTAQueueSize();
    }

    if (commandLine.hasOption(certStoreSizeOption.getOpt())) {
        retrieveCertStoreSize();
    }

    if (commandLine.hasOption(certRequestStoreSizeOption.getOpt())) {
        retrieveCertRequestStoreSize();
    }

    if (commandLine.hasOption(smsSizeOption.getOpt())) {
        retrieveSMSSize();
    }

    if (commandLine.hasOption(userSizeOption.getOpt())) {
        retrieveUsersSize();
    }
}

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

/**
 * Test where java flag is set false//from   w  w  w . jav a 2s.co  m
 */
public void testjavaFlagSetFalse() {
    log.info("java flag set false");
    Options options = new Options();
    options.addOption("java", false, "only format java files");
    options.addOption("groovy", false, "only format groovy files");
    CommandLine cmd = null;
    CommandLineParser parser = new BasicParser();
    try {
        cmd = parser.parse(options, new String[] { "-groovy" });
    } catch (ParseException e) {
        log.error(e, e);
    }
    assertTrue("java flag set false", Formatter.javaFormatting(cmd) == false);
}

From source file:edu.uthscsa.ric.papaya.builder.Builder.java

@SuppressWarnings("static-access")
private CommandLine createCLI(final String[] args) {
    this.options = new Options();
    this.options.addOption(new Option(ARG_SAMPLE, "include sample image"));
    this.options.addOption(new Option(ARG_LOCAL, "build for local usage"));
    this.options.addOption(new Option(ARG_SINGLE, "output a single HTML file"));
    this.options.addOption(new Option(ARG_HELP, "print this message"));
    this.options.addOption(OptionBuilder.withArgName("files").hasArgs().withDescription("images to include")
            .create(ARG_IMAGE));//from ww  w .  ja v  a 2  s .c  o m
    this.options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("papaya project directory")
            .create(ARG_ROOT));
    this.options.addOption(
            OptionBuilder.withArgName("file").hasOptionalArg().withDescription("add atlas").create(ARG_ATLAS));
    this.options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("specify parameters")
            .create(ARG_PARAM_FILE));
    this.options.addOption(
            OptionBuilder.withArgName("text").hasArg().withDescription("add a title").create(ARG_TITLE));

    final CommandLineParser parser = new BasicParser();
    CommandLine line = null;

    try {
        line = parser.parse(this.options, args, true);
    } catch (final ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
    }

    return line;
}