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

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

Introduction

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

Prototype

public ParseException(String message) 

Source Link

Document

Construct a new ParseException with the specified detail message.

Usage

From source file:lcmc.LCMC.java

/** Parse cluster options and create cluster button. */
private static void parseClusterOptions(final CommandLine cmd) throws ParseException {
    String clusterName = null;//w w  w  .ja  v a2  s .  co  m
    List<HostOptions> hostsOptions = null;
    final Map<String, List<HostOptions>> clusters = new LinkedHashMap<String, List<HostOptions>>();
    for (final Option option : cmd.getOptions()) {
        final String op = option.getLongOpt();
        if (CLUSTER_OP.equals(op)) {
            clusterName = option.getValue();
            if (clusterName == null) {
                throw new ParseException("could not parse " + CLUSTER_OP + " option");

            }
            clusters.put(clusterName, new ArrayList<HostOptions>());
        } else if (HOST_OP.equals(op)) {
            final String[] hostNames = option.getValues();
            if (clusterName == null) {
                clusterName = "default";
                clusters.put(clusterName, new ArrayList<HostOptions>());
            }
            if (hostNames == null) {
                throw new ParseException("could not parse " + HOST_OP + " option");
            }
            hostsOptions = new ArrayList<HostOptions>();
            for (final String hostNameEntered : hostNames) {
                String hostName;
                String port = null;
                if (hostNameEntered.indexOf(':') > 0) {
                    final String[] he = hostNameEntered.split(":");
                    hostName = he[0];
                    port = he[1];
                    if ("".equals(port) || !Tools.isNumber(port)) {
                        throw new ParseException("could not parse " + HOST_OP + " option");
                    }
                } else {
                    hostName = hostNameEntered;
                }
                final HostOptions ho = new HostOptions(hostName);
                if (port != null) {
                    ho.setPort(port);
                }
                hostsOptions.add(ho);
                clusters.get(clusterName).add(ho);
            }
        } else if (SUDO_OP.equals(op)) {
            if (hostsOptions == null) {
                throw new ParseException(SUDO_OP + " must be defined after " + HOST_OP);
            }
            for (final HostOptions ho : hostsOptions) {
                ho.setSudo(true);
            }
        } else if (USER_OP.equals(op)) {
            if (hostsOptions == null) {
                throw new ParseException(USER_OP + " must be defined after " + HOST_OP);
            }
            final String userName = option.getValue();
            if (userName == null) {
                throw new ParseException("could not parse " + USER_OP + " option");
            }
            for (final HostOptions ho : hostsOptions) {
                ho.setUser(userName);
            }
        } else if (PORT_OP.equals(op)) {
            if (hostsOptions == null) {
                throw new ParseException(PORT_OP + " must be defined after " + HOST_OP);
            }
            final String port = option.getValue();
            if (port == null) {
                throw new ParseException("could not parse " + PORT_OP + " option");
            }
            for (final HostOptions ho : hostsOptions) {
                ho.setPort(port);
            }
        }
    }
    for (final String cn : clusters.keySet()) {
        for (final HostOptions hostOptions : clusters.get(cn)) {
            if (hostsOptions.size() < 1
                    || (hostsOptions.size() == 1 && !Tools.getConfigData().isOneHostCluster())) {
                throw new ParseException("not enough hosts for cluster: " + cn);
            }
        }
    }
    final String failedHost = Tools.setUserConfigFromOptions(clusters);
    if (failedHost != null) {
        Tools.appWarning("could not resolve host \"" + failedHost + "\" skipping");
    }
}

From source file:bdsup2sub.cli.CommandLineParser.java

private void parsePaletteFileOption(CommandLine line) throws ParseException {
    if (line.hasOption(PALETTE_FILE)) { //TODO: only sub/idx
        String value = line.getOptionValue(PALETTE_FILE);
        paletteFile = new File(value);
        if (!paletteFile.exists()) {
            throw new ParseException("Palette file not found: " + value);
        } else {/* www . ja v  a  2 s. c  o  m*/
            if (!Arrays.equals("#COL".getBytes(), ToolBox.getFileID(value, 4))) {
                throw new ParseException("Invalid palette file: " + value);
            }
        }
    }
}

From source file:edu.uci.ics.asterix.aoya.AsterixYARNClient.java

/**
 * Cursory sanity checks for argument sanity, without considering the mode of the client
 * // ww  w. ja va 2  s .c  om
 * @param args
 * @param cliParser
 *            The parsed arguments.
 * @throws ParseException
 */
private void checkConfSanity(String[] args, CommandLine cliParser) throws ParseException {
    String message = null;

    //Sanity check for no args 
    if (args.length == 0) {
        message = "No args specified for client to initialize";
    }
    //AM memory should be a sane value
    else if (amMemory < 0) {
        message = "Invalid memory specified for application master, exiting." + " Specified memory=" + amMemory;
    }
    //we're good!
    else {
        return;
    }
    //default:
    throw new ParseException(message);

}

From source file:edu.uci.ics.asterix.aoya.AsterixYARNClient.java

/**
 * Initialize the mode of the client from the arguments.
 * //from ww  w . j ava 2s .c om
 * @param args
 * @param cliParser
 * @throws ParseException
 */
private void initMode(String[] args, CommandLine cliParser) throws ParseException {
    @SuppressWarnings("unchecked")
    List<String> clientVerb = cliParser.getArgList();
    String message = null;
    //Now check if there is a mode
    if (clientVerb == null || clientVerb.size() < 1) {
        message = "You must specify an action.";
    }
    //But there can only be one mode...
    else if (clientVerb.size() > 1) {
        message = "Trailing arguments, or too many arguments. Only one action may be performed at a time.";
    }
    if (message != null) {
        throw new ParseException(message);
    }
    //Now we can initialize the mode and check it against parameters
    mode = Mode.fromAlias(clientVerb.get(0));
    if (mode == null) {
        mode = Mode.NOOP;
    }
}

From source file:com.bigdata.dastor.tools.DastorAdminCli.java

public static DastorAdminCli initCli(String[] args, ArrayList<String> cmdArgList)
        throws IOException, InterruptedException, ParseException {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//from   w  w w  .ja va2 s  .co  m

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException parseExcep) {
        System.err.println(parseExcep);
        printUsage();
        System.exit(1);
    }

    String host = cmd.getOptionValue(HOST_OPT_LONG);
    int port = defaultPort;

    String portNum = cmd.getOptionValue(PORT_OPT_LONG);
    if (portNum != null) {
        try {
            port = Integer.parseInt(portNum);
        } catch (NumberFormatException e) {
            throw new ParseException("Port must be a number");
        }
    }

    NodeProbe probe = null;
    try {
        probe = new NodeProbe(host, port);
    } catch (IOException ioe) {
        System.err.println("Error connecting to remote JMX agent!");
        ioe.printStackTrace();
        System.exit(3);
    }
    System.out.println("connected to " + host + ":" + port);

    for (String arg : cmd.getArgs()) {
        cmdArgList.add(arg);
    }

    return new DastorAdminCli(probe, host, port);
}

From source file:edu.upenn.ircs.lignos.morsel.MorphLearner.java

/**
 * Call the learner on the specified arguments. Exit using standard error codes
 * (sysexits.h) if an error is encountered.
 * @param args command line arguments//  w w  w . j  av  a  2s. c o  m
 */
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();
    // Set up command line arguments
    Options options = new Options();
    options.addOption(new Option("h", "help", false, "dislay this help and exit"));
    Option encodingOption = new Option("e", "encoding", true,
            "input and output file encoding. Defaults to ISO8859_1.");
    encodingOption.setArgName("encoding");
    options.addOption(encodingOption);
    options.addOption(new Option("b", "base-inf", false,
            "output the examples of base inference. This does not change whether base inference"
                    + " is used; it simply outputs the examples that used it."));
    options.addOption(new Option("s", "conflation-sets", false, "output the learner's conflation sets"));
    options.addOption(new Option("c", "compounds", false,
            "output the learner's analsyis before final compounding is used"));
    HelpFormatter formatter = new HelpFormatter();
    String usage = "MorphLearner [options] wordlist outfile logfile paramfile";

    CommandLine line = null;
    String[] otherArgs = null;
    try {
        // Parse the command line arguments
        line = parser.parse(options, args);
        otherArgs = line.getArgs();

        // Handle help
        if (line.hasOption("help")) {
            formatter.printHelp(usage, options);
            System.exit(0);
        }

        if (otherArgs.length != 4) {
            throw new ParseException("Incorrect number of required arguments specified");
        }
    } catch (ParseException exp) {
        System.out.println(exp.getMessage());
        formatter.printHelp(usage, options);
        System.exit(64);
    }

    // Get options
    String encoding = line.getOptionValue("encoding", "ISO8859_1");
    boolean outputBaseInf = line.hasOption("base-inf");
    boolean outputConflation = line.hasOption("conflation-sets");
    boolean outputCompounds = line.hasOption("compounds");

    // Setup timing
    long start;
    float elapsedSeconds;
    start = System.currentTimeMillis();

    // Initialize the learner
    MorphLearner learner = null;
    try {
        learner = new MorphLearner(otherArgs[0], otherArgs[1], otherArgs[2], otherArgs[3], encoding,
                outputBaseInf, outputConflation, outputCompounds);
    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
        System.exit(66);
    } catch (UnsupportedEncodingException e) {
        System.err.println("Unsupported file encoding: " + encoding);
        System.exit(74);
    }

    // Output time stats
    elapsedSeconds = (System.currentTimeMillis() - start) / 1000F;
    System.out.println("Init time: " + elapsedSeconds + "s\n");

    // Time learning
    start = System.currentTimeMillis();

    learner.learn();
    learner.cleanUp();

    // Output time stats
    elapsedSeconds = (System.currentTimeMillis() - start) / 1000F;
    System.out.println("\nLearning time: " + elapsedSeconds + "s");
}

From source file:edu.uci.ics.asterix.aoya.AsterixYARNClient.java

/**
 * Determine if the command line arguments are sufficient for the requested client mode.
 * /*from w  ww . j a  va2  s . c om*/
 * @param args
 *            The command line arguments.
 * @param cliParser
 *            Parsed command line arguments.
 * @throws ParseException
 */

private void checkModeSanity(String[] args, CommandLine cliParser) throws ParseException {

    String message = null;
    //The only time you can use the client without specifiying an instance, is to list all of the instances it sees.
    if (!cliParser.hasOption("name") && mode != Mode.DESCRIBE) {
        message = "You must give a name for the instance to be acted upon";
    } else if (mode == Mode.INSTALL && !cliParser.hasOption("asterixConf")) {
        message = "No Configuration XML given. Please specify a config for cluster installation";
    } else if (mode != Mode.START && cliParser.hasOption("refresh")) {
        message = "Cannot specify refresh in any mode besides start, mode is: " + mode;
    } else if (cliParser.hasOption("snapshot") && !(mode == Mode.RESTORE || mode == Mode.RMBACKUP)) {
        message = "Cannot specify a snapshot to restore in any mode besides restore or rmbackup, mode is: "
                + mode;
    } else if ((mode == Mode.ALTER || mode == Mode.INSTALL) && baseConfig == null
            && !(new File(DEFAULT_PARAMETERS_PATH).exists())) {
        message = "Default asterix parameters file is not in the default location, and no custom location is specified";
    }
    //nothing is wrong, so exit
    else {
        return;
    }
    //otherwise, something is bad.
    throw new ParseException(message);

}

From source file:com.archivas.clienttools.arcmover.cli.ManagedCLIJob.java

protected boolean handleRerunAndResume(CommandLine cmdLine, LoadSchedule schedule) throws ParseException {
    boolean result = false;

    String whichCmd = null;//from  w  w w .j a  va  2 s .c  om
    if (cmdLine.hasOption(RERUN) && cmdLine.hasOption(RESUME)) {
        throw new ParseException(
                "Cannot use both --resume and --rerun.  Please use just one.  Consult your manual if you have questions.");
    } else if (cmdLine.hasOption(RERUN)) {
        whichCmd = RERUN;
    } else if (cmdLine.hasOption(RESUME)) {
        whichCmd = RESUME;
    }

    if (whichCmd != null) {
        try {
            managedJobImpl = getManagedJobImplFromCmdLine(cmdLine, whichCmd);

            // Error Handling
            // Rerun only works on not completed jobs
            // Resume only works on completed jobs that have no failed objects
            if (whichCmd.equals(RERUN)) {
                if (managedJobImpl.getStatus() != JobStatus.COMPLETED) {
                    throw new ParseException(
                            "The job with this job name: \"" + managedJobImpl.getJob().getJobName()
                                    + "\" has not completed.  Please run this job using --resume.");
                }

                if (managedJobImpl.getFailedObjectCount() == 0) {
                    throw new ParseException(
                            "The job with this job name: \"" + managedJobImpl.getJob().getJobName()
                                    + "\" has already run to completion and has no failed files.");
                }
            } else if (whichCmd.equals(RESUME)) {
                if (managedJobImpl.getStatus() == JobStatus.COMPLETED) {
                    throw new ParseException("The job with this job name: \""
                            + managedJobImpl.getJob().getJobName()
                            + "\" has already run to completion.  Please run that job with --rerun if there were failed files.");
                }
            }

            managedJob = managedJobImpl.getJob();
            if (cmdLine.hasOption(RERUN) || cmdLine.hasOption(RESUME)) {
                LoadSchedule RerunResumeSchedule = managedJob.getLoadSchedule();
                getLoadSchedule(cmdLine, RerunResumeSchedule);
                managedJob.setLoadSchedule(RerunResumeSchedule);
            } else {
                managedJob.setLoadSchedule(schedule);
            }

            // Flush the stats
            arcMover.getManagedJobDetails(managedJobImpl, true);

            result = true;
        } catch (JobNotFoundException e) {
            throw new ParseException(
                    "JobNotFoundException which trying to " + whichCmd + " a job.  Msg: " + e.getMessage());
        } catch (DatabaseException e) {
            throw new ParseException(
                    "DatabaseException trying to get job to " + whichCmd + " a job.  Msg: " + e.getMessage());
        } catch (JobException e) {
            throw new ParseException(
                    "JobException trying to initialize job to " + whichCmd + " .  Msg: " + e.getMessage());
        }
    }
    return result;
}

From source file:be.ugent.intec.halvade.HalvadeOptions.java

protected boolean parseArguments(String[] args, Configuration halvadeConf) throws ParseException {
    createOptions();//from   ww w  .  ja  v a  2 s . c  o m
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(options, args);

    in = line.getOptionValue("I");
    out = line.getOptionValue("O");
    if (!out.endsWith("/"))
        out += "/";
    ref = line.getOptionValue("R");
    sites = line.getOptionValue("D");
    halvadeBinaries = line.getOptionValue("B");
    hdfsSites = sites.split(",");
    if (line.hasOption("bam")) {
        useBamInput = true;
    }
    if (line.hasOption("rna")) {
        rnaPipeline = true;
        if (line.hasOption("star"))
            STARGenome = line.getOptionValue("star");
        if (!useBamInput && STARGenome == null) {
            throw new ParseException(
                    "the '-rna' option requires --star pointing to the location of the STAR reference directory if alignment with STAR aligner is required (fastq).");
        }
    }

    if (line.hasOption("tmp")) {
        tmpDir = line.getOptionValue("tmp");
    }
    if (line.hasOption("stargtf")) {
        stargtf = line.getOptionValue("stargtf");
    }
    if (line.hasOption("refdir")) {
        localRefDir = line.getOptionValue("refdir");
        if (!localRefDir.endsWith("/"))
            localRefDir += "/";
    }
    if (line.hasOption("nodes")) {
        nodes = Integer.parseInt(line.getOptionValue("nodes"));
    }
    if (line.hasOption("vcores")) {
        vcores = Integer.parseInt(line.getOptionValue("vcores"));
    }
    if (line.hasOption("smt")) {
        smtEnabled = true;
    }
    if (line.hasOption("remove_dups")) {
        keepDups = false;
    }
    if (line.hasOption("mem")) {
        mem = Double.parseDouble(line.getOptionValue("mem"));
    }
    if (line.hasOption("rpr")) {
        readCountsPerRegionFile = line.getOptionValue("rpr");
    }
    if (line.hasOption("mpn")) {
        setMapContainers = false;
        mapContainersPerNode = Integer.parseInt(line.getOptionValue("mpn"));
    }
    if (line.hasOption("rpn")) {
        setReduceContainers = false;
        reducerContainersPerNode = Integer.parseInt(line.getOptionValue("rpn"));
    }
    if (line.hasOption("mapmem")) {
        overrideMapMem = (int) (Double.parseDouble(line.getOptionValue("mapmem")) * 1024);
    }
    if (line.hasOption("redmem")) {
        overrideRedMem = (int) (Double.parseDouble(line.getOptionValue("redmem")) * 1024);
    }
    if (line.hasOption("scc")) {
        stand_call_conf = Integer.parseInt(line.getOptionValue("scc"));
    }
    if (line.hasOption("sec")) {
        stand_emit_conf = Integer.parseInt(line.getOptionValue("sec"));
    }
    if (line.hasOption("count")) {
        countOnly = true;
    }
    if (line.hasOption("report_all")) {
        reportAll = true;
    }
    if (line.hasOption("illumina")) {
        fixQualEnc = true;
    }
    if (line.hasOption("keep")) {
        keepFiles = true;
    }
    if (line.hasOption("update_rg")) {
        updateRG = true;
    }
    if (line.hasOption("redistribute")) {
        redistribute = true;
    }
    if (line.hasOption("single")) {
        paired = false;
    }
    if (line.hasOption("justalign")) {
        justAlign = true;
        combineVcf = false;
    }
    if (line.hasOption("aln")) {
        aln = Integer.parseInt(line.getOptionValue("aln"));
        if (aln < 0 || aln > 3)
            aln = 0; // default value
    }
    if (line.hasOption("J")) {
        java = line.getOptionValue("J");
    }
    if (line.hasOption("gff")) {
        gff = line.getOptionValue("gff");
    }
    if (line.hasOption("dryrun")) {
        dryRun = true;
        combineVcf = false;
    }
    if (line.hasOption("drop")) {
        keepChrSplitPairs = false;
    }
    //        if (line.hasOption("cov")) {
    //            coverage = Double.parseDouble(line.getOptionValue("cov"));
    //        }
    if (line.hasOption("merge_bam")) {
        mergeBam = true;
    }
    if (line.hasOption("c")) {
        justCombine = true;
        combineVcf = true;
    }
    if (line.hasOption("filter_dbsnp")) {
        filterDBSnp = true;
    }
    if (line.hasOption("reorder_regions")) {
        reorderRegions = true;
    }
    if (line.hasOption("haplotypecaller")) {
        useGenotyper = false;
    }
    if (line.hasOption("elprep")) {
        useElPrep = true;
    }
    if (line.hasOption("id")) {
        RGID = line.getOptionValue("id");
    }
    if (line.hasOption("lb")) {
        RGLB = line.getOptionValue("lb");
    }
    if (line.hasOption("pl")) {
        RGPL = line.getOptionValue("pl");
    }
    if (line.hasOption("pu")) {
        RGPU = line.getOptionValue("pu");
    }
    if (line.hasOption("sm")) {
        RGSM = line.getOptionValue("sm");
    }
    if (line.hasOption("bed")) {
        bedFile = line.getOptionValue("bed");
    }
    if (line.hasOption("fbed")) {
        filterBed = line.getOptionValue("fbed");
    }
    if (line.hasOption("v")) {
        Logger.SETLEVEL(Integer.parseInt(line.getOptionValue("v")));
    }

    if (line.hasOption("CA")) {
        Properties props = line.getOptionProperties("CA");
        Enumeration names = props.propertyNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            addCustomArguments(halvadeConf, name, props.getProperty(name));
        }
    }
    return true;
}

From source file:com.archivas.clienttools.arcmover.cli.ArcCopy.java

private String validateTargetPath(CommandLine cmdLine) throws ParseException {
    if (!cmdLine.hasOption(DESTINATION_PATH_OPTION)) {
        throw new ParseException("Missing Option: " + DESTINATION_PATH_OPTION);
    }/*w w  w.j a v a  2 s  .  co m*/

    String value = cmdLine.getOptionValue(DESTINATION_PATH_OPTION);
    String retval = null;

    if (value != null) {
        retval = value;
    }
    if (retval == null) {
        throw new ParseException("Invalid " + DESTINATION_PATH_OPTION + " : " + value);
    }
    return retval;
}