Example usage for org.apache.commons.cli Option setRequired

List of usage examples for org.apache.commons.cli Option setRequired

Introduction

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

Prototype

public void setRequired(boolean required) 

Source Link

Document

Sets whether this Option is mandatory.

Usage

From source file:edu.mit.csail.sdg.alloy4.Terminal.java

/**
 * @param args/*from  w  ww . j  ava  2s.co  m*/
 * @throws Exception
 */
public static int execute(String[] args) throws Exception {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options optionsArg = new Options();
    Option helpOpt = new Option("?", "help", false, "print this message");
    Option alloyOpt = new Option("alloy", true, "the alloy input file to check");
    alloyOpt.setRequired(true);
    Option commandOpt = new Option("c", "command", true, "the command to run");
    Option runAllCommandsOpt = new Option("a", "runall", false, "run all commands");
    Option keepResultsOpt = new Option("k", "keep", false, "keep result files");
    Option solverOpt = new Option("s", "solver", true,
            "name of SAT Solver. Options are: " + getAvaliableSatSolvers());

    optionsArg.addOption(helpOpt);
    optionsArg.addOption(alloyOpt);
    optionsArg.addOption(commandOpt);
    optionsArg.addOption(runAllCommandsOpt);
    optionsArg.addOption(keepResultsOpt);
    optionsArg.addOption(solverOpt);

    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(optionsArg, args);

        if (line.hasOption(helpOpt.getOpt())) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("vdm2alloy", optionsArg);
            return 0;
        }

    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("vdm2alloy", optionsArg);
        return 1;
    }

    String intputAlloyModel = null;
    if (line.hasOption(alloyOpt.getOpt())) {
        intputAlloyModel = line.getOptionValue(alloyOpt.getOpt());
    }

    // Setup solver and alloy libs
    copyFromJAR();

    A4Reporter rep = new A4Reporter();

    A4Options options = new A4Options();

    options.solver = A4Options.SatSolver.MiniSatProverJNI;
    if (line.hasOption(solverOpt.getOpt())) {
        String solverName = line.getOptionValue(solverOpt.getOpt());
        A4Options.SatSolver solver = getSolver(solverName);
        if (solver == null) {
            System.err.println("Solver could not be resolved with value: " + solverName);
            return 1;
        }
        options.solver = solver;
    }

    Module someWorld = null;
    try {
        someWorld = CompUtil.parseEverything_fromFile(rep, null, intputAlloyModel);
        System.out.println();
    } catch (Err e) {
        System.err.println(e);
        System.err.println();
        System.err.flush();
        return 1;
    }

    List<Command> commandsToRun = new Vector<Command>();

    if (line.hasOption(commandOpt.getOpt())) {
        String commandName = line.getOptionValue(commandOpt.getOpt());
        for (Command command : someWorld.getAllCommands()) {
            if (command.label.equals(commandName)) {
                commandsToRun.add(command);
                break;
            }
        }
        if (commandsToRun.isEmpty()) {
            System.err.println("Command: " + commandName + " not found in " + someWorld.getAllCommands());
            return 1;
        }
    }

    if (commandsToRun.isEmpty() || line.hasOption(runAllCommandsOpt.getOpt())) {
        commandsToRun.addAll(someWorld.getAllCommands());
    }

    System.out.println("Alloy Analysis");
    int i = 0;
    for (Command command : commandsToRun) {
        i++;
        A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, someWorld.getAllReachableSigs(), command,
                options);
        show(ans, commandsToRun, command, i);

        if (line.hasOption(keepResultsOpt.getOpt())) {
            final String tempdir = alloyHome() + fs + "binary" + File.separatorChar;
            if (ans.satisfiable()) {
                ans.writeXML(tempdir + "tmp" + i + "cnf.xml");
            }
            final File tempCNF = new File(tempdir + "tmp.cnf");
            copyFile(tempCNF, new File(tempdir + "tmp" + i + ".cnf"));
        }
    }
    System.out.println("Done.");
    return 0;
}

From source file:mitm.common.tools.SendMail.java

@SuppressWarnings("static-access")
private static Options createCommandLineOptions() {
    Options options = new Options();

    Option hostOption = OptionBuilder.withArgName("host").hasArg().withDescription("smtp host").create("h");
    hostOption.setRequired(false);
    options.addOption(hostOption);/*from   w  w  w. j ava 2 s. c  o  m*/

    Option portOption = OptionBuilder.withArgName("port").hasArg().withDescription("smtp port").create("p");
    portOption.setRequired(false);
    options.addOption(portOption);

    Option usernameOption = OptionBuilder.withArgName("username").hasArg().withDescription("username")
            .create("u");
    usernameOption.setRequired(false);
    options.addOption(usernameOption);

    Option passwordPromptOption = OptionBuilder.withArgName("p").withDescription("ask for password")
            .create("pwd");
    passwordPromptOption.setRequired(false);
    options.addOption(passwordPromptOption);

    Option passwordOption = OptionBuilder.withArgName("password").hasArg().withDescription("password")
            .create("password");
    passwordOption.setRequired(false);
    options.addOption(passwordOption);

    Option senderOption = OptionBuilder.withArgName("sender").hasArg()
            .withDescription("enveloped sender (MAIL FROM)").create("s");
    senderOption.setRequired(false);
    options.addOption(senderOption);

    Option subjectOption = OptionBuilder.withArgName("subject").hasArg().withDescription("subject")
            .create("su");
    subjectOption.setRequired(false);
    options.addOption(subjectOption);

    Option fromOption = OptionBuilder.withArgName("from").hasArg().withDescription("from (header)").create("f");
    fromOption.setRequired(false);
    options.addOption(fromOption);

    Option recipientsOption = OptionBuilder.withArgName("recipients").hasArg()
            .withDescription("comma separated recipients").create("r");
    recipientsOption.setRequired(false);
    options.addOption(recipientsOption);

    Option inOption = OptionBuilder.withArgName("email file").hasArg().withDescription("input file (rfc 2822)")
            .create("in");
    inOption.setRequired(false);
    options.addOption(inOption);

    Option countOption = OptionBuilder.withArgName("count").hasArg().withDescription("count").create("c");
    countOption.setRequired(false);
    options.addOption(countOption);

    Option threadsOption = OptionBuilder.withArgName("threads").hasArg().withDescription("number of threads")
            .create("t");
    threadsOption.setRequired(false);
    options.addOption(threadsOption);

    Option delayOption = OptionBuilder.withArgName("delay").hasArg().withDescription("delay in milliseconds")
            .create("d");
    delayOption.setRequired(false);
    options.addOption(delayOption);

    Option listenOption = OptionBuilder.withArgName("listen").withDescription("listen for incoming SMTP")
            .create("l");
    listenOption.setRequired(false);
    options.addOption(listenOption);

    Option throttlingOption = OptionBuilder.withArgName("throttling").hasArg().withDescription("throttle send")
            .create("throttle");
    throttlingOption.setRequired(false);
    options.addOption(throttlingOption);

    Option serverPortOption = OptionBuilder.withArgName("port").hasArg().withDescription("smtp server port")
            .create("serverPort");
    serverPortOption.setRequired(false);
    options.addOption(serverPortOption);

    Option uniqueFromOption = OptionBuilder.withDescription("prefix the from with an increasing counter")
            .create("uf");
    uniqueFromOption.setRequired(false);
    options.addOption(uniqueFromOption);

    return options;
}

From source file:com.twitter.hraven.etl.JobFilePartitioner.java

/**
 * Parse command-line arguments./*from w  w w.  ja v  a2s  .  c o m*/
 * 
 * @param args
 *          command line arguments passed to program.
 * @return parsed command line.
 * @throws ParseException
 */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Input
    Option o = new Option("i", "input", true, "input directory as hdfs path, or local as file://");
    o.setArgName("input-path");
    o.setRequired(true);
    options.addOption(o);

    // Input
    o = new Option("o", "output", true, "output directory");
    o.setArgName("input-path");
    o.setRequired(true);
    options.addOption(o);

    // Whether to skip existing files or not.
    o = new Option("s", "skipExisting", false, "skip existing files. Cannot be used together with m for move.");
    o.setRequired(false);
    options.addOption(o);

    // Maximum number of files to retain in the specified input directory.
    o = new Option("x", "maXretention", true,
            "The maximum number of the most recent files to retain in the input directory after processing."
                    + " Can be used by HDFS input paths only. Mutually exclusive with s (move),"
                    + " but can be used in combination with s (skipExisting)");
    o.setRequired(false);
    options.addOption(o);

    // Whether files need to be moved
    o = new Option("m", "move", false,
            "move all files rather than copying." + "Delete source if target already exists."
                    + " Can be used with HDFS input paths only. " + " Mutually exlusive with s (skipExisting)");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");
    o.setRequired(false);
    options.addOption(o);

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }

    return commandLine;
}

From source file:fr.inria.atlanmod.dag.instantiator.Launcher.java

/**
 * Configures the program options//ww  w .  ja va 2 s  . co m
 *
 * @param options
 */
private static void configureOptions(Options options) {

    Option outDirOpt = OptionBuilder.create(OUTPUT_PATH);
    outDirOpt.setLongOpt(OUTPUT_PATH_LONG);
    outDirOpt.setArgName("neoEMF output uri");
    outDirOpt.setDescription("Output directory (defaults to working dir)");
    outDirOpt.setArgs(1);
    outDirOpt.setRequired(true);

    Option nModelsOpt = OptionBuilder.create(N_MODELS);
    nModelsOpt.setLongOpt(N_MODELS_LONG);
    nModelsOpt.setArgName("models");
    nModelsOpt.setDescription("Number of generated models (defaults to 1)");
    nModelsOpt.setType(Number.class);
    nModelsOpt.setArgs(1);

    Option sizeOption = OptionBuilder.create(SIZE);
    sizeOption.setLongOpt(SIZE_LONG);
    sizeOption.setArgName("size");
    sizeOption.setDescription(MessageFormat.format("Average models'' size (defaults to {0})",
            Launcher.DEFAULT_AVERAGE_MODEL_SIZE));
    sizeOption.setType(Number.class);
    sizeOption.setArgs(1);

    Option densityOption = OptionBuilder.create(VARIATION);
    densityOption.setLongOpt(VARIATION_LONG);
    densityOption.setArgName("proportion");
    densityOption.setDescription(MessageFormat
            .format("Variation ([0..1]) in the models'' size (defaults to {0})", Launcher.DEFAULT_DEVIATION));
    densityOption.setType(Number.class);
    densityOption.setArgs(1);

    Option propVariationOption = OptionBuilder.create(PROP_VARIATION);
    propVariationOption.setLongOpt(PROP_VARIATION_LONG);
    propVariationOption.setArgName("properties deviation");
    propVariationOption.setDescription(MessageFormat.format(
            "Variation ([0..1]) in the properties'' size (defaults to {0})", Launcher.DEFAULT_DEVIATION));
    propVariationOption.setType(Number.class);
    propVariationOption.setArgs(1);

    Option seedOption = OptionBuilder.create(SEED);
    seedOption.setLongOpt(SEED_LONG);
    seedOption.setArgName("seed");
    seedOption.setDescription("Seed number (random by default)");
    seedOption.setType(Number.class);
    seedOption.setArgs(1);

    Option valuesSizeOption = OptionBuilder.create(VALUES_SIZE);
    valuesSizeOption.setLongOpt(VALUES_SIZE_LONG);
    valuesSizeOption.setArgName("size");
    valuesSizeOption.setDescription(MessageFormat.format(
            "Average size for attributes with variable length (defaults to {0}). Actual sizes may vary +/- {1}%.",
            GenericMetamodelConfig.DEFAULT_AVERAGE_VALUES_LENGTH,
            GenericMetamodelConfig.DEFAULT_VALUES_DEVIATION * 100));
    valuesSizeOption.setType(Number.class);
    valuesSizeOption.setArgs(1);

    Option degreeOption = OptionBuilder.create(DEGREE);
    degreeOption.setLongOpt(DEGREE_LONG);
    degreeOption.setArgName("degree");
    degreeOption.setDescription(MessageFormat.format(
            "Average number of references per EObject (defaults to {0}). Actual sizes may vary +/- {1}%.",
            GenericMetamodelConfig.DEFAULT_AVERAGE_REFERENCES_SIZE,
            GenericMetamodelConfig.DEFAULT_REFERENCES_DEVIATION * 100));
    degreeOption.setType(Number.class);
    degreeOption.setArgs(1);

    Option forceOption = OptionBuilder.create(FORCE);
    forceOption.setLongOpt(FORCE_LONG);
    forceOption.setDescription("Force the generation, even if input metamodels contain errors");

    Option diagnoseOption = OptionBuilder.create(DIAGNOSE);
    diagnoseOption.setLongOpt(DIAGNOSE_LONG);
    diagnoseOption.setDescription("Run diagnosis on the result model");

    options.addOption(outDirOpt);
    options.addOption(nModelsOpt);
    options.addOption(sizeOption);
    options.addOption(propVariationOption);
    options.addOption(valuesSizeOption);
    options.addOption(degreeOption);
    options.addOption(seedOption);
    options.addOption(forceOption);
    options.addOption(diagnoseOption);
    options.addOption(densityOption);
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.Launcher.java

/**
 * Configures the program options/*from  w  ww.ja  va  2s .co m*/
 *
 * @param options
 */
private static void configureOptions(Options options) {
    Option metamodelOpt = OptionBuilder.create(E_PACKAGE_CLASS);
    metamodelOpt.setLongOpt(E_PACKAGE_CLASS_LONG);
    metamodelOpt.setArgName("path to the ePackage implementation");
    metamodelOpt.setDescription("PackgeImpl");
    metamodelOpt.setArgs(1);
    metamodelOpt.setRequired(true);

    Option outDirOpt = OptionBuilder.create(OUTPUT_PATH);
    outDirOpt.setLongOpt(OUTPUT_PATH_LONG);
    outDirOpt.setArgName("neoEMF output uri");
    outDirOpt.setDescription("Output directory (defaults to working dir)");
    outDirOpt.setArgs(1);
    outDirOpt.setRequired(true);

    Option nModelsOpt = OptionBuilder.create(N_MODELS);
    nModelsOpt.setLongOpt(N_MODELS_LONG);
    nModelsOpt.setArgName("models");
    nModelsOpt.setDescription("Number of generated models (defaults to 1)");
    nModelsOpt.setType(Number.class);
    nModelsOpt.setArgs(1);

    Option sizeOption = OptionBuilder.create(SIZE);
    sizeOption.setLongOpt(SIZE_LONG);
    sizeOption.setArgName("size");
    sizeOption.setDescription(MessageFormat.format("Average models'' size (defaults to {0})",
            Launcher.DEFAULT_AVERAGE_MODEL_SIZE));
    sizeOption.setType(Number.class);
    sizeOption.setArgs(1);

    Option variationOption = OptionBuilder.create(VARIATION);
    variationOption.setLongOpt(VARIATION_LONG);
    variationOption.setArgName("proportion");
    variationOption.setDescription(MessageFormat
            .format("Variation ([0..1]) in the models'' size (defaults to {0})", Launcher.DEFAULT_DEVIATION));
    variationOption.setType(Number.class);
    variationOption.setArgs(1);

    Option propVariationOption = OptionBuilder.create(PROP_VARIATION);
    propVariationOption.setLongOpt(PROP_VARIATION_LONG);
    propVariationOption.setArgName("properties deviation");
    propVariationOption.setDescription(MessageFormat.format(
            "Variation ([0..1]) in the properties'' size (defaults to {0})", Launcher.DEFAULT_DEVIATION));
    propVariationOption.setType(Number.class);
    propVariationOption.setArgs(1);

    Option seedOption = OptionBuilder.create(SEED);
    seedOption.setLongOpt(SEED_LONG);
    seedOption.setArgName("seed");
    seedOption.setDescription("Seed number (random by default)");
    seedOption.setType(Number.class);
    seedOption.setArgs(1);

    Option valuesSizeOption = OptionBuilder.create(VALUES_SIZE);
    valuesSizeOption.setLongOpt(VALUES_SIZE_LONG);
    valuesSizeOption.setArgName("size");
    valuesSizeOption.setDescription(MessageFormat.format(
            "Average size for attributes with variable length (defaults to {0}). Actual sizes may vary +/- {1}%.",
            GenericMetamodelConfig.DEFAULT_AVERAGE_VALUES_LENGTH,
            GenericMetamodelConfig.DEFAULT_VALUES_DEVIATION * 100));
    valuesSizeOption.setType(Number.class);
    valuesSizeOption.setArgs(1);

    Option degreeOption = OptionBuilder.create(DEGREE);
    degreeOption.setLongOpt(DEGREE_LONG);
    degreeOption.setArgName("degree");
    degreeOption.setDescription(MessageFormat.format(
            "Average number of references per EObject (defaults to {0}). Actual sizes may vary +/- {1}%.",
            GenericMetamodelConfig.DEFAULT_AVERAGE_REFERENCES_SIZE,
            GenericMetamodelConfig.DEFAULT_REFERENCES_DEVIATION * 100));
    degreeOption.setType(Number.class);
    degreeOption.setArgs(1);

    Option forceOption = OptionBuilder.create(FORCE);
    forceOption.setLongOpt(FORCE_LONG);
    forceOption.setDescription("Force the generation, even if input metamodels contain errors");

    Option diagnoseOption = OptionBuilder.create(DIAGNOSE);
    diagnoseOption.setLongOpt(DIAGNOSE_LONG);
    diagnoseOption.setDescription("Run diagnosis on the result model");

    options.addOption(metamodelOpt);
    options.addOption(outDirOpt);
    options.addOption(nModelsOpt);
    options.addOption(sizeOption);
    options.addOption(variationOption);
    options.addOption(propVariationOption);
    options.addOption(valuesSizeOption);
    options.addOption(degreeOption);
    options.addOption(seedOption);
    options.addOption(forceOption);
    options.addOption(diagnoseOption);
}

From source file:de.uni_koblenz.ist.utilities.license_header.LicenseHeader.java

private static CommandLine processCommandLineOptions(String[] args) {
    OptionHandler oh = new OptionHandler("java " + LicenseHeader.class.getName(), "1.0");
    Option input = new Option("i", "input", true, "(required): The file or directory to process.");
    // input.setArgs(1);
    input.setRequired(true);
    input.setArgName("fileOrDirectory");
    oh.addOption(input);/*from w w w  .j  a  v  a2s.co  m*/

    Option licenceHeader = new Option("l", "licence", true,
            "(required): The file containing the licence header in the correct format. This file should be in plain text without any language specific syntax for comments.");
    // licenceHeader.setArgs(1);
    licenceHeader.setRequired(true);
    licenceHeader.setArgName("licenseFile");
    oh.addOption(licenceHeader);

    // TODO add this feature
    // Option fileType = new Option(
    // "x",
    // "--xml",
    // false,
    // "(optional): This flag tells the program to operate on xml files instead of java files (experimental).");
    // fileType.setRequired(false);
    // oh.addOption(fileType);

    Option recursive = new Option("r", "recursive", false,
            "(optional): This flag tells the program to process the given directory fully recursively. If only a file is given, this option is ignored. If this flag is not set, only the given directory is processed, without subdirectories.");
    recursive.setRequired(false);
    oh.addOption(recursive);

    Option verbose = new Option("V", "verbose", false,
            "(optional): This flag tells the program to be more verbose while processing the files. If it is not set, only a summary will be given in the end.");
    verbose.setRequired(false);
    oh.addOption(verbose);

    return oh.parse(args);
}

From source file:mitm.common.tools.SMIME.java

@SuppressWarnings("static-access")
private static Options createCommandLineOptions() {
    Options options = new Options();

    Option inOption = OptionBuilder.withArgName("in").hasArg().withDescription("input file").create("in");
    inOption.setRequired(false);
    options.addOption(inOption);/*from ww  w  .  j a  v a2s  .  c  o  m*/

    Option keyStoreOption = OptionBuilder.withArgName("p12").hasArg().withDescription("keystore (.p12/.pfx)")
            .create("p12");
    keyStoreOption.setRequired(false);
    options.addOption(keyStoreOption);

    Option passwordOption = OptionBuilder.withArgName("password").hasArg().withDescription("password")
            .create("password");
    passwordOption.setRequired(false);
    options.addOption(passwordOption);

    Option passwordPromptOption = OptionBuilder.withDescription("ask for password").create("pwd");
    passwordPromptOption.setRequired(false);
    options.addOption(passwordPromptOption);

    Option helpOption = OptionBuilder.withDescription("Show help").create("help");
    helpOption.setRequired(false);
    options.addOption(helpOption);

    Option p7mOption = OptionBuilder.withDescription("file is a p7m file").create("p7m");
    p7mOption.setRequired(false);
    options.addOption(p7mOption);

    Option p7mOutputOption = OptionBuilder.withArgName("p7m output file").hasArg()
            .withDescription("save the p7m as S/MIME to p7mOut").create("p7mOut");
    p7mOutputOption.setRequired(false);
    options.addOption(p7mOutputOption);

    Option binaryOption = OptionBuilder.withDescription("file is binary").create("binary");
    binaryOption.setRequired(false);
    options.addOption(binaryOption);

    Option cerOutputOption = OptionBuilder.withArgName("cer output file").hasArg()
            .withDescription("saves the certificates from the signed blob to this file in p7b format.")
            .create("cerOut");
    cerOutputOption.setRequired(false);
    options.addOption(cerOutputOption);

    Option readOption = OptionBuilder.withDescription("read S/MIME file").create("r");
    readOption.setRequired(false);
    options.addOption(readOption);

    Option signOption = OptionBuilder.withDescription("sign file").create("sign");
    signOption.setRequired(false);
    options.addOption(signOption);

    Option keyAliasOption = OptionBuilder.withArgName("alias").hasArg().withDescription("key alias")
            .create("alias");
    keyAliasOption.setRequired(false);
    options.addOption(keyAliasOption);

    Option printAliasesOption = OptionBuilder.withDescription("print key aliases").create("printAliases");
    printAliasesOption.setRequired(false);
    options.addOption(printAliasesOption);

    Option digestOption = OptionBuilder.withDescription("hash algorithm").hasArg()
            .withDescription("digest hash algorithm").create("digest");
    digestOption.setRequired(false);
    options.addOption(digestOption);

    Option outOption = OptionBuilder.withDescription("output file").hasArg().withDescription("output file")
            .create("out");
    outOption.setRequired(false);
    options.addOption(outOption);

    return options;
}

From source file:de.pniehus.odal.App.java

/**S
 * Parses the command line arguments/*from  ww w .  java 2  s  . c o m*/
 * 
 * @param args
 * @param filters
 * @return
 */
public static Profile parseArgs(String[] args, List<Filter> filters) {
    boolean windowsConsole = false;

    Profile profile = new Profile(filters);

    Options options = new Options();
    Options helpOptions = new Options();

    Option profileOption = Option.builder("p").longOpt("profile").hasArg().argName("profile name")
            .desc("Loads or generates the profile with the given name").build();

    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        Console console = System.console();
        if (console != null) {
            windowsConsole = true;
            profileOption.setRequired(true);
        }
    }

    options.addOption(profileOption);
    options.addOption(Option.builder("url").hasArg().argName("url")
            .desc("Sets the url of the open directory which will be parsed and downloaded").build());
    options.addOption(Option.builder("a").longOpt("select-all").desc(
            "Downloads all available files (except the ones removed by filters), overrules the corresponding setting if a profile is used")
            .build());
    options.addOption(Option.builder("o").longOpt("outputDir").hasArg().argName("directory path").desc(
            "Sets the output directory to the given directory, overrules the corresponding setting if a profile is used")
            .build());
    options.addOption(Option.builder("w").longOpt("windows-mode")
            .desc("Enables the windows console mode on non-windows systems. Requires -url and -p to be used.")
            .build());
    Option helpOption = Option.builder("h").longOpt("help").desc("Displays this help dialog").build();

    helpOptions.addOption(helpOption);
    options.addOption(helpOption);

    CommandLineParser cliParser = new DefaultParser();

    try {
        CommandLine cmd = cliParser.parse(helpOptions, args, true);

        if (cmd.getOptions().length == 0) {
            cmd = cliParser.parse(options, args);

            if (cmd.hasOption("w")) {
                windowsConsole = true;
                if (!cmd.hasOption("p")) {
                    System.out.println("ERROR: The profile option is required for windows mode!");
                    printHelp(filters, options);
                }
            }

            if (cmd.hasOption("p")) {
                String profileName = cmd.getOptionValue("p");
                File profileFile = new File(profileName + ".odal");
                if (profileFile.exists()) {
                    try {
                        profile = Profile.loadProfile(profileName);
                        profile.setUserProfile(true);
                    } catch (IOException e) {
                        System.out.println("An error occured while loading the specified profile!");
                    }
                } else {
                    try {
                        Profile.saveProfile(profileName, profile);
                        System.out.println("The profile " + profileFile.getName() + " has been created!");
                        System.exit(0);
                    } catch (IOException e) {
                        System.out.println("An error occured during the creation of the profile "
                                + profileFile.getName() + " : " + e.getMessage());
                        System.out.println("Terminating.");
                        System.exit(1);
                    }
                }

            }

            if (cmd.hasOption("a")) {
                profile.setSelectAll(true);
            }

            if (cmd.hasOption("o")) {
                File out = new File(cmd.getOptionValue("o"));
                if (out.isDirectory() || out.canWrite()) {
                    profile.setOutputPath(out.getAbsolutePath());
                } else {
                    System.out.println(out.getAbsolutePath() + " is not a directory or not writeable!");
                    System.out.println("Terminating.");
                    System.exit(1);
                }
            }

            if (cmd.hasOption("url")) {
                profile.setUrl(cmd.getOptionValue("url"));
            } else if (windowsConsole) {
                System.out.println("ERROR: The -url argument is required for console use on windows systems.");
                printHelp(filters, options);
                System.exit(1);
            }

        } else {
            printHelp(filters, options);
            System.exit(0);
        }
    } catch (ParseException e) {
        System.out.println("\nUnable to parse command line arguments: " + e.getLocalizedMessage() + "\n");
        printHelp(filters, options);
        System.exit(1);
    }

    if (windowsConsole) {
        profile.setWindowsConsoleMode(true);
    }

    return profile;
}

From source file:com.tc.config.schema.setup.BaseConfigurationSetupManagerTest.java

private static Options createOptions(ConfigMode configMode) {
    Options options = new Options();

    Option configFileOption = new Option("f", CONFIG_SPEC_ARGUMENT_NAME, true,
            "the configuration file to use, specified as a file path or URL");
    configFileOption.setArgName("file-or-URL");
    configFileOption.setType(String.class);

    if (configMode == ConfigMode.L2) {
        configFileOption.setRequired(false);
        options.addOption(configFileOption);

        Option l2NameOption = new Option("n", "name", true, "the name of this L2; defaults to the host name");
        l2NameOption.setRequired(false);
        l2NameOption.setArgName("l2-name");
        options.addOption(l2NameOption);
    } else {//from   w ww .  ja v  a2s  .  c  om
        configFileOption.setRequired(true);
        options.addOption(configFileOption);
    }

    return options;
}

From source file:fr.inria.atlanmod.instantiator.SpecimenGenerator.java

/**
 * Configures the program options// w w w  .ja v a 2s .com
 *
 * @param options
 */
private static void configureOptions(Options options) {
    Option metamodelOpt = OptionBuilder.create(METAMODEL);
    metamodelOpt.setLongOpt(METAMODEL_LONG);
    metamodelOpt.setArgName("path_to_metamodel.ecore");
    metamodelOpt.setDescription("Ecore metamodel");
    metamodelOpt.setArgs(1);
    metamodelOpt.setRequired(true);

    Option additionalMetamodelOpt = OptionBuilder.create(ADDITIONAL_METAMODEL);
    additionalMetamodelOpt.setLongOpt(ADDITIONAL_METAMODEL_LONG);
    additionalMetamodelOpt.setArgName("path_to_metamodel.ecore");
    additionalMetamodelOpt.setDescription("Additional ecore metamodel(s) that need to be registered");
    additionalMetamodelOpt.setArgs(Option.UNLIMITED_VALUES);

    Option outDirOpt = OptionBuilder.create(OUTPUT_DIR);
    outDirOpt.setLongOpt(OUTPUT_DIR_LONG);
    outDirOpt.setArgName("path_to_output.dir");
    outDirOpt.setDescription("Output directory (defaults to working dir)");
    outDirOpt.setArgs(1);

    Option nModelsOpt = OptionBuilder.create(N_MODELS);
    nModelsOpt.setLongOpt(N_MODELS_LONG);
    nModelsOpt.setArgName("models");
    nModelsOpt.setDescription("Number of generated models (defaults to 1)");
    nModelsOpt.setType(Number.class);
    nModelsOpt.setArgs(1);

    Option sizeOption = OptionBuilder.create(SIZE);
    sizeOption.setLongOpt(SIZE_LONG);
    sizeOption.setArgName("size");
    sizeOption.setDescription("Models' size (defaults to 1000)");
    sizeOption.setType(Number.class);
    sizeOption.setArgs(1);

    Option seedOption = OptionBuilder.create(SEED);
    seedOption.setLongOpt(SEED_LONG);
    seedOption.setArgName("seed");
    seedOption.setDescription("Seed number (random by default)");
    seedOption.setType(Number.class);
    seedOption.setArgs(1);

    options.addOption(metamodelOpt);
    options.addOption(additionalMetamodelOpt);
    options.addOption(outDirOpt);
    options.addOption(nModelsOpt);
    options.addOption(sizeOption);
    options.addOption(seedOption);
}