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

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

Introduction

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

Prototype

public void setType(Object type) 

Source Link

Document

Sets the type of this Option.

Usage

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 {/*  ww w. ja  v a 2 s .  c o m*/
        configFileOption.setRequired(true);
        options.addOption(configFileOption);
    }

    return options;
}

From source file:com.springrts.springls.CmdLineArgs.java

private static Options createOptions() {

    Configuration defaults = ServerConfiguration.getDefaults();

    Options options = new Options();

    Option help = new Option(null, "help", false, "Print this help message.");
    options.addOption(help);/*from www .j  a  v a2 s.co  m*/

    Option port = new Option("p", "port", true,
            String.format("The main (TCP) port number to host on [1, 65535]." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.PORT)));
    // possible types:
    // * File.class
    // * Number.class
    // * Class.class
    // * Object.class
    // * Url.class
    port.setType(Number.class);
    port.setArgName("port-number");
    options.addOption(port);

    Option statistics = new Option(null, "statistics", false,
            "Whether to create and save statistics to disc on predefined" + " intervals.");
    options.addOption(statistics);

    Option natPort = new Option("n", "nat-port", true,
            String.format(
                    "The (UDP) port number to host the NAT traversal techniques"
                            + " help service on [1, 65535], which lets clients detect their"
                            + " source port, for example when using \"hole punching\"." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.NAT_PORT)));
    port.setType(Number.class);
    natPort.setArgName("NAT-port-number");
    options.addOption(natPort);

    Option logMain = new Option(null, "log-main", false,
            String.format("Whether to log all conversations from channel #main to \"%s\"",
                    Channel.createDefaultActivityLogFilePath("main").getPath()));
    options.addOption(logMain);

    Option lanAdmin = new Option(null, "lan-admin", true,
            String.format(
                    "The LAN mode admin account. Use this account to administer"
                            + " your LAN server. The default is \"%s\", with password \"%s\".",
                    defaults.getString(ServerConfiguration.LAN_ADMIN_USERNAME),
                    defaults.getString(ServerConfiguration.LAN_ADMIN_PASSWORD)));
    lanAdmin.setArgName("username");
    options.addOption(lanAdmin);

    Option loadArgs = new Option(null, "load-args", true,
            "Will read command-line arguments from the specified file."
                    + " You can freely combine actual command-line arguments with"
                    + " the ones from the file. If duplicate args are specified,"
                    + " the last one will prevail.");
    loadArgs.setArgName("filename");
    port.setType(File.class);
    options.addOption(loadArgs);

    Option springVersion = new Option(null, "spring-version", true,
            "Will set the latest Spring version to this string."
                    + " The default is \"*\". This is used to tell clients which"
                    + " version is the latest one, so that they know when to" + " update.");
    springVersion.setArgName("version");
    options.addOption(springVersion);

    Option useStorageDb = new Option(null, "database", false,
            "Use a DB for user accounts and ban entries." + " This disables \"LAN mode\".");
    options.addOption(useStorageDb);

    Option useStorageFile = new Option(null, "file-storage", false,
            "Use the (deprecated) accounts.txt for user accounts." + " This disables \"LAN mode\".");
    options.addOption(useStorageFile);

    OptionGroup storageOG = new OptionGroup();
    storageOG.addOption(useStorageDb);
    storageOG.addOption(useStorageFile);
    options.addOptionGroup(storageOG);

    return options;
}

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

/**
 * Configures the program options//w w  w  .java 2s .  c  o  m
 *
 * @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);
}

From source file:fr.ujm.tse.lt2c.satin.main.Main.java

/**
 * @param args//from w  w w.j a v a  2  s.co  m
 * @return a ReasoningArguements object containing all the parsed arguments
 */
private static ReasoningArguments getArguments(final String[] args) {

    /* Reasoner fields */
    int threadsNB = DEFAULT_THREADS_NB;
    int bufferSize = DEFAULT_BUFFER_SIZE;
    long timeout = DEFAULT_TIMEOUT;
    int iteration = 1;
    ReasonerProfile profile = DEFAULT_PROFILE;

    /* Extra fields */
    boolean verboseMode = DEFAULT_VERBOSE_MODE;
    boolean warmupMode = DEFAULT_WARMUP_MODE;
    boolean dumpMode = DEFAULT_DUMP_MODE;
    boolean batchMode = DEFAULT_BATCH_MODE;

    /*
     * Options
     */

    final Options options = new Options();

    final Option bufferSizeO = new Option("b", "buffer-size", true, "set the buffer size");
    bufferSizeO.setArgName("size");
    bufferSizeO.setArgs(1);
    bufferSizeO.setType(Number.class);
    options.addOption(bufferSizeO);

    final Option timeoutO = new Option("t", "timeout", true,
            "set the buffer timeout in ms (0 means timeout will be disabled)");
    bufferSizeO.setArgName("time");
    bufferSizeO.setArgs(1);
    bufferSizeO.setType(Number.class);
    options.addOption(timeoutO);

    final Option iterationO = new Option("i", "iteration", true, "how many times each file ");
    iterationO.setArgName("number");
    iterationO.setArgs(1);
    iterationO.setType(Number.class);
    options.addOption(iterationO);

    final Option directoryO = new Option("d", "directory", true, "infers on all ontologies in the directory");
    directoryO.setArgName("directory");
    directoryO.setArgs(1);
    directoryO.setType(File.class);
    options.addOption(directoryO);

    options.addOption("o", "output", false, "save output into file");

    options.addOption("h", "help", false, "print this message");

    options.addOption("v", "verbose", false, "enable verbose mode");

    options.addOption("r", "batch-reasoning", false, "enable batch reasoning");

    options.addOption("w", "warm-up", false, "insert a warm-up lap before the inference");

    final Option profileO = new Option("p", "profile", true,
            "set the fragment " + java.util.Arrays.asList(ReasonerProfile.values()));
    profileO.setArgName("profile");
    profileO.setArgs(1);
    options.addOption(profileO);

    final Option threadsO = new Option("n", "threads", true,
            "set the number of threads by available core (0 means the jvm manage)");
    threadsO.setArgName("number");
    threadsO.setArgs(1);
    threadsO.setType(Number.class);
    options.addOption(threadsO);

    /*
     * Arguments parsing
     */
    final CommandLineParser parser = new GnuParser();
    final CommandLine cmd;
    try {
        cmd = parser.parse(options, args);

    } catch (final ParseException e) {
        LOGGER.error("", e);
        return null;
    }

    /* help */
    if (cmd.hasOption("help")) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("main", options);
        return null;
    }

    /* buffer */
    if (cmd.hasOption("buffer-size")) {
        final String arg = cmd.getOptionValue("buffer-size");
        try {
            bufferSize = Integer.parseInt(arg);
        } catch (final NumberFormatException e) {
            LOGGER.error("Buffer size must be a number. Default value used", e);
        }
    }
    /* timeout */
    if (cmd.hasOption("timeout")) {
        final String arg = cmd.getOptionValue("timeout");
        try {
            timeout = Integer.parseInt(arg);
        } catch (final NumberFormatException e) {
            LOGGER.error("Timeout must be a number. Default value used", e);
        }
    }
    /* verbose */
    if (cmd.hasOption("verbose")) {
        verboseMode = true;
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Verbose mode enabled");
        }
    }
    /* warm-up */
    if (cmd.hasOption("warm-up")) {
        warmupMode = true;
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Warm-up mode enabled");
        }
    }
    /* dump */
    if (cmd.hasOption("output")) {
        dumpMode = true;
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Dump mode enabled");
        }
    }
    /* dump */
    if (cmd.hasOption("batch-reasoning")) {
        batchMode = true;
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Batch mode enabled");
        }
    }
    /* directory */
    String dir = null;
    if (cmd.hasOption("directory")) {
        for (final Object o : cmd.getOptionValues("directory")) {
            String arg = o.toString();
            if (arg.startsWith("~" + File.separator)) {
                arg = System.getProperty("user.home") + arg.substring(1);
            }
            final File directory = new File(arg);
            if (!directory.exists()) {
                LOGGER.warn("**Cant not find " + directory);
            } else if (!directory.isDirectory()) {
                LOGGER.warn("**" + directory + " is not a directory");
            } else {
                dir = directory.getAbsolutePath();
            }
        }
    }
    /* profile */
    if (cmd.hasOption("profile")) {
        final String string = cmd.getOptionValue("profile");
        switch (string) {
        case "RhoDF":
            profile = ReasonerProfile.RHODF;
            break;
        case "BRhoDF":
            profile = ReasonerProfile.BRHODF;
            break;
        case "RDFS":
            profile = ReasonerProfile.RDFS;
            break;
        case "BRDFS":
            profile = ReasonerProfile.BRDFS;
            break;

        default:
            LOGGER.warn("Profile unknown, default profile used: " + DEFAULT_PROFILE);
            profile = DEFAULT_PROFILE;
            break;
        }
    }
    /* threads */
    if (cmd.hasOption("threads")) {
        final String arg = cmd.getOptionValue("threads");
        try {
            threadsNB = Integer.parseInt(arg);
        } catch (final NumberFormatException e) {
            LOGGER.error("Threads number must be a number. Default value used", e);
        }
    }
    /* iteration */
    if (cmd.hasOption("iteration")) {
        final String arg = cmd.getOptionValue("iteration");
        try {
            iteration = Integer.parseInt(arg);
        } catch (final NumberFormatException e) {
            LOGGER.error("Iteration must be a number. Default value used", e);
        }
    }

    final List<File> files = new ArrayList<>();
    if (dir != null) {
        final File directory = new File(dir);
        final File[] listOfFiles = directory.listFiles();

        for (final File file : listOfFiles) {
            // Maybe other extensions ?
            if (file.isFile() && file.getName().endsWith(".nt")) {
                files.add(file);
            }
        }
    }
    for (final Object o : cmd.getArgList()) {
        String arg = o.toString();
        if (arg.startsWith("~" + File.separator)) {
            arg = System.getProperty("user.home") + arg.substring(1);
        }
        final File file = new File(arg);
        if (!file.exists()) {
            LOGGER.warn("**Cant not find " + file);
        } else if (file.isDirectory()) {
            LOGGER.warn("**" + file + " is a directory");
        } else {
            files.add(file);
        }
    }

    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(final File f1, final File f2) {
            if (f1.length() > f2.length()) {
                return 1;
            }
            if (f2.length() > f1.length()) {
                return -1;
            }
            return 0;
        }
    });

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("********* OPTIONS *********");
        LOGGER.info("Buffer size:      " + bufferSize);
        LOGGER.info("Profile:          " + profile);
        if (threadsNB > 0) {
            LOGGER.info("Threads:          " + threadsNB);
        } else {
            LOGGER.info("Threads:          Automatic");
        }
        LOGGER.info("Iterations:       " + iteration);
        LOGGER.info("Timeout:          " + timeout);
        LOGGER.info("***************************");
    }

    return new ReasoningArguments(threadsNB, bufferSize, timeout, iteration, profile, verboseMode, warmupMode,
            dumpMode, batchMode, files);

}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, String description, Class<?> type, boolean isRequired) {
    Option option = new Option(opt, description);
    option.setType(type);
    option.setRequired(isRequired);//from   ww  w .  j  a  v  a2  s . c o m

    options.addOption(option);
}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, String description, Class<?> type, boolean isRequired, String argName) {
    Option option = new Option(opt, description);
    option.setType(type);
    option.setRequired(isRequired);/*  w ww.j  a v a  2s.  c om*/
    option.setArgName(argName);

    options.addOption(option);
}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, boolean hasArg, String description, Class<?> type, boolean isRequired) {
    Option option = new Option(opt, hasArg, description);
    option.setType(type);
    option.setRequired(isRequired);/*from  w  w  w.  ja v a2 s  .c  om*/

    options.addOption(option);
}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, boolean hasArg, String description, Class<?> type, boolean isRequired,
        String argName) {/*  w  ww.jav  a 2s.  co  m*/
    Option option = new Option(opt, hasArg, description);
    option.setType(type);
    option.setRequired(isRequired);
    option.setArgName(argName);

    options.addOption(option);
}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, String longOpt, boolean hasArg, String description, Class<?> type,
        boolean isRequired) {
    Option option = new Option(opt, longOpt, hasArg, description);
    option.setType(type);
    option.setRequired(isRequired);//ww w  .  ja  v  a2s .  com
    options.addOption(option);
}

From source file:com.tc.cli.CommandLineBuilder.java

public void addOption(String opt, String longOpt, boolean hasArg, String description, Class<?> type,
        boolean isRequired, String argName) {
    Option option = new Option(opt, longOpt, hasArg, description);
    option.setType(type);
    option.setRequired(isRequired);//from   w w w .  j a  va 2 s . com
    option.setArgName(argName);

    options.addOption(option);
}