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

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

Introduction

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

Prototype

public UnrecognizedOptionException(String message) 

Source Link

Document

Construct a new UnrecognizedArgumentException with the specified detail message.

Usage

From source file:jlite.cli.JobMatch.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();/*from   w ww  . ja v a 2  s  . c o m*/
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setSyntaxPrefix("Usage: ");
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
        if (line.hasOption("help")) {
            helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false);
            System.out.println(); // extra line
            System.exit(0);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            String[] remArgs = line.getArgs();
            if (remArgs.length == 1) {
                run(remArgs[0], line);
            } else if (remArgs.length == 0) {
                throw new MissingArgumentException("Missing required argument: <jdl_file>");
            } else {
                throw new UnrecognizedOptionException("Unrecognized extra arguments");
            }
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage() + "\n");
        helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false);
        System.out.println(); // extra line
        System.exit(-1);
    } catch (Exception e) {
        if (line.hasOption("xml")) {
            System.out.println("<error>" + e.getMessage() + "</error>");
        } else {
            System.err.println(e.getMessage());
        }
    } finally {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:jlite.cli.JobSubmit.java

public static void main(String[] args) {
    System.out.println(); // extra line
    CommandLineParser parser = new GnuParser();
    Options options = setupOptions();//from  ww w.ja  v  a2  s .c om
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setSyntaxPrefix("Usage: ");
    CommandLine line = null;

    try {
        line = parser.parse(options, args);
        if (line.hasOption("help")) {
            helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false);
            System.out.println(); // extra line
            System.exit(0);
        } else {
            if (line.hasOption("xml")) {
                System.out.println("<output>");
            }
            String[] remArgs = line.getArgs();
            if (remArgs.length == 1) {
                run(remArgs[0], line);
            } else if (remArgs.length == 0) {
                throw new MissingArgumentException("Missing required argument: <jdl_file>");
            } else {
                throw new UnrecognizedOptionException("Unrecognized extra arguments");
            }
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage() + "\n");
        helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false);
        System.out.println(); // extra line
        System.exit(-1);
    } catch (Exception e) {
        if (line.hasOption("xml")) {
            System.out.println("<error>" + e.getMessage() + "</error>");
        } else {
            System.err.println(e.getMessage());
        }
    } finally {
        if (line.hasOption("xml")) {
            System.out.println("</output>");
        }
    }
    System.out.println(); // extra line
}

From source file:fdtutilscli.Main.java

/**
 * /*from  www.  jav a  2  s. c  om*/
 * @param args the command line arguments
 */
public static void main(String[] args) {

    CommandLineParser parser = new PosixParser();
    CommandLine line = null;
    Options options = new Options();
    OptionGroup optCommand = new OptionGroup();
    OptionGroup optOutput = new OptionGroup();
    HelpFormatter formatter = new HelpFormatter();
    TRACE trace = TRACE.DEFAULT;

    optCommand.addOption(OptionBuilder.withArgName("ndf odf nif key seperator").hasArgs(5)
            .withValueSeparator(' ').withDescription("Description").create("delta"));
    optCommand.addOption(OptionBuilder.withArgName("dupsfile key seperator").hasArgs(3)
            .withDescription("Description").create("duplicates"));
    optCommand.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message.").create("h"));
    optCommand.addOption(
            OptionBuilder.withLongOpt("version").withDescription("print version information.").create("V"));
    optOutput.addOption(new Option("verbose", "be extra verbose"));
    optOutput.addOption(new Option("quiet", "be extra quiet"));
    optOutput.addOption(new Option("silent", "same as --quiet"));
    options.addOptionGroup(optCommand);
    options.addOptionGroup(optOutput);

    try {
        line = parser.parse(options, args);

        if (line.hasOption("verbose")) {
            trace = TRACE.VERBOSE;
        } else if (line.hasOption("quiet") || line.hasOption("silent")) {
            trace = TRACE.QUIET;
        }

        if (line.hasOption("h")) {
            formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true);
            return;
        } else if (line.hasOption("V")) {
            System.out.println(APP_NAME + " version " + VERSION);
            System.out.println("fDTDeltaBuilder version " + DTDeltaBuilder.version());
            System.out.println("DTDuplicateKeyFinder version " + DTDuplicateKeyFinder.version());
            return;
        } else if (line.hasOption("delta")) {
            String ndf = line.getOptionValues("delta")[0];
            String odf = line.getOptionValues("delta")[1];
            String nif = line.getOptionValues("delta")[2];
            Integer key = (line.getOptionValues("delta").length <= 3) ? DEFAULT_KEY
                    : new Integer(line.getOptionValues("delta")[3]);
            String seperator = (line.getOptionValues("delta").length <= 4) ? DEFAULT_SEPERATOR
                    : line.getOptionValues("delta")[4];

            doDelta(ndf, odf, nif, key.intValue(), seperator, trace);

            return;
        } else if (line.hasOption("duplicates")) {
            String dupsFile = line.getOptionValues("duplicates")[0];
            Integer key = (line.getOptionValues("duplicates").length <= 1) ? DEFAULT_KEY
                    : new Integer(line.getOptionValues("duplicates")[1]);
            String seperator = (line.getOptionValues("duplicates").length <= 2) ? DEFAULT_SEPERATOR
                    : line.getOptionValues("duplicates")[2];
            doDuplicates(dupsFile, key.intValue(), seperator, trace);
            return;
        } else if (args.length == 0) {
            formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true);
        } else {
            throw new UnrecognizedOptionException(E_MSG_UNREC_OPT);
        }

    } catch (UnrecognizedOptionException e) {
        formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true);
    } catch (ParseException e) {
        formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true);
    }
}

From source file:dioscuri.CommandLineInterface.java

/**
 * Creates a CommandLineInterface with the provided parameters
 *
 * @param parameters the parameters to be parsed
 * @throws Exception when there are invalid parameters
 *//*from www .j  a  v a  2s . c  o m*/
public CommandLineInterface(String... parameters) throws Exception {

    initOptions();
    parse(parameters);

    help = commandLine.hasOption("?");
    exit = commandLine.hasOption("e");
    hide = commandLine.hasOption("h");
    visible = !hide;
    autorun = commandLine.hasOption("r");
    autoshutdown = commandLine.hasOption("s");

    if (commandLine.hasOption("?")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar Dioscuri.jar [OPTIONS]\n", commandLineOptions);
        System.exit(0);
    }

    // a custom config file is used
    if (commandLine.hasOption("c")) {
        File cfg = Utilities.resolvePathAsFile(commandLine.getOptionValue("c"));
        logger.log(Level.INFO, "using custom config file: " + cfg);
        if (cfg == null || !cfg.exists()) {
            throw new IOException(" [cli] config file '" + cfg.getName() + "' does not exist in folder '"
                    + cfg.getParentFile().getAbsolutePath() + "'");
        }
        configFilePath = cfg.getAbsolutePath();
    } else {
        configFilePath = Constants.DEFAULT_CONFIG_XML;
    }
    loadConfigFile();

    boolean changes = false;

    if (commandLine.hasOption("f")) {
        File floppyImg = Utilities.resolvePathAsFile(commandLine.getOptionValue("f"));
        logger.log(Level.INFO, " [cli] using custom floppy image: " + floppyImg);
        if (floppyImg == null || !floppyImg.exists()) {
            throw new IOException(" [cli] floppy image '" + floppyImg.getName() + "' does not exist in folder '"
                    + floppyImg.getParentFile().getAbsolutePath() + "'");
        }
        emuConfig.getArchitecture().getModules().getFdc().getFloppy().get(0)
                .setImagefilepath(floppyImg.getAbsolutePath());
        changes = true;
    }

    if (commandLine.hasOption("d1")) {
        File hdImg = Utilities.resolvePathAsFile(commandLine.getOptionValue("d1"));
        logger.log(Level.INFO, " [cli] using custom first hard disk image: " + hdImg);
        if (hdImg == null || !hdImg.exists() || !hdImg.isFile()) {
            emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(0).setEnabled(false);
            throw new IOException(" [cli] hard disk image '" + hdImg.getName() + "' does not exist in folder '"
                    + hdImg.getParentFile().getAbsolutePath() + "'");
        }
        emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(0)
                .setImagefilepath(hdImg.getAbsolutePath());
        emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(0).setEnabled(true);
        changes = true;
    }

    if (commandLine.hasOption("d2")) {
        File hdImg = Utilities.resolvePathAsFile(commandLine.getOptionValue("d2"));
        logger.log(Level.INFO, " [cli] using custom second hard disk image: " + hdImg);
        if (hdImg == null || !hdImg.exists() || !hdImg.isFile()) {
            emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(1).setEnabled(false);
            throw new IOException(" [cli] hard disk image '" + hdImg.getName() + "' does not exist in folder '"
                    + hdImg.getParentFile().getAbsolutePath() + "'");
        }
        emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(1)
                .setImagefilepath(hdImg.getAbsolutePath());
        emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(1).setEnabled(true);
        changes = true;
    }

    if (commandLine.hasOption("a")) {
        String val = commandLine.getOptionValue("a");
        int bits;
        if (val.matches("16|32")) {
            bits = Integer.valueOf(val);
        } else {
            throw new UnrecognizedOptionException("illegal architecture value: " + val);
        }
        logger.log(Level.INFO, " [cli] setting cpu architecture to: " + bits + " bits");
        emuConfig.getArchitecture().getModules().getCpu().setCpu32Bit(bits == 32);
        changes = true;
    }

    if (commandLine.hasOption("b")) {
        String val = commandLine.getOptionValue("b").toLowerCase();
        String floppy = "Floppy Drive";
        String hd = "Hard Drive";
        boolean hdEnabled = true;
        String boot = hd;
        if (val.matches("floppy|harddisk")) {
            if (val.equals("floppy")) {
                hdEnabled = false;
                boot = floppy;
            }
        } else {
            throw new UnrecognizedOptionException("illegal boot value: " + boot);
        }
        logger.log(Level.INFO, " [cli] setting boot drive: " + val);
        emuConfig.getArchitecture().getModules().getBios().get(0).getBootdrives().setBootdrive0(boot);
        if (hdEnabled) {
            emuConfig.getArchitecture().getModules().getAta().getHarddiskdrive().get(0).setEnabled(true);
        } else {
            emuConfig.getArchitecture().getModules().getFdc().getFloppy().get(0).setEnabled(true);
        }
        changes = true;
    }

    if (commandLine.hasOption("m")) {
        String val = commandLine.getOptionValue("m").toLowerCase();
        boolean enabled;
        if (val.matches("enabled|disabled")) {
            enabled = val.equals("enabled");
        } else {
            throw new UnrecognizedOptionException(
                    "illegal value: " + val + ", expected 'enabled' or 'disabled'.");
        }
        logger.log(Level.INFO, " [cli] mouse enabled? " + enabled);
        emuConfig.getArchitecture().getModules().getMouse().setEnabled(enabled);
        changes = true;
    }

    if (changes) {
        Utilities.saveXML(emuConfig, configFilePath);
    }
}

From source file:com.continuent.tungsten.common.security.PasswordManagerCtrl.java

/**
 * Get the application type argument.//w w w  .j av a2  s.  c o m
 * Populates the <code>clientApplicationType</code> property
 * 
 * @param commandLineTargetApplicationType the argument provided on the
 *            command line
 * @return a ClientApplicationType
 * @throws UnrecognizedOptionException if the cast could not be made
 */
private static ClientApplicationType getClientApplicationType(String commandLineTargetApplicationType)
        throws UnrecognizedOptionException {
    try {
        clientApplicationType = ClientApplicationType.fromString(commandLineTargetApplicationType);
    } catch (IllegalArgumentException iae) {
        throw new UnrecognizedOptionException(MessageFormat
                .format("The target application type does not exist: {0}", commandLineTargetApplicationType));
    }

    return clientApplicationType;
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.ClientRMService.java

private ReservationACL getReservationACLFromAuditConstant(String auditConstant) throws YarnException {
    if (auditConstant.equals(AuditConstants.SUBMIT_RESERVATION_REQUEST)) {
        return ReservationACL.SUBMIT_RESERVATIONS;
    } else if (auditConstant.equals(AuditConstants.LIST_RESERVATION_REQUEST)) {
        return ReservationACL.LIST_RESERVATIONS;
    } else if (auditConstant.equals(AuditConstants.DELETE_RESERVATION_REQUEST)
            || auditConstant.equals(AuditConstants.UPDATE_RESERVATION_REQUEST)) {
        return ReservationACL.ADMINISTER_RESERVATIONS;
    } else {/*from w  ww  .j a  v a 2 s  . c  om*/
        String error = "Audit Constant " + auditConstant + " is not recognized.";
        LOG.error(error);
        throw RPCUtil.getRemoteException(new UnrecognizedOptionException(error));
    }
}

From source file:org.apache.parquet.tools.command.ArgsOnlyCommand.java

@Override
public void execute(CommandLine options) throws Exception {
    String[] args = options.getArgs();
    if (args.length < min) {
        throw new MissingArgumentException("missing required arguments");
    }/*from w ww .j  a v  a 2s  . c o  m*/

    if (args.length > max) {
        throw new UnrecognizedOptionException("unknown extra argument \"" + args[max] + "\"");
    }
}