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

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

Introduction

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

Prototype

public void setArgName(String argName) 

Source Link

Document

Sets the display name for the argument value.

Usage

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

/**
 * @param args/* w ww . j a  v a2  s .  com*/
 * @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:kieker.tools.bridge.cli.CLIServerMain.java

/**
 * Compile the options for the CLI server.
 *
 * @return The composed options for the CLI server
 *//*from  w  w w.  j av a 2 s  .c  o  m*/
private static Options declareOptions() {
    options = new Options();
    Option option;

    // Type selection
    option = new Option(CMD_TYPE, CMD_TYPE_LONG, true,
            "select the service type: tcp-client, tcp-server, tcp-single-server, jms-client, jms-embedded, http-rest");
    option.setArgName("type");
    option.setRequired(true);
    options.addOption(option);

    // TCP client
    option = new Option(CMD_HOST, CMD_HOST_LONG, true, "connect to server named <hostname>");
    option.setArgName("hostname");
    options.addOption(option);

    // TCP server
    option = new Option(CMD_PORT, CMD_PORT_LONG, true,
            "listen at port (tcp-server, jms-embedded, or http-rest) or connect to port (tcp-client)");
    option.setArgName("number");
    option.setType(Number.class);
    options.addOption(option);

    // JMS client
    option = new Option(CMD_USER, CMD_USER_LONG, true, "user name for a JMS service");
    option.setArgName("username");
    options.addOption(option);
    option = new Option(CMD_PASSWORD, CMD_PASSWORD_LONG, true, "password for a JMS service");
    option.setArgName("password");
    options.addOption(option);
    option = new Option(CMD_URL, CMD_URL_LONG, true, "URL for JMS server or HTTP servlet");
    option.setArgName("jms-url");
    option.setType(URL.class);
    options.addOption(option);

    // HTTP client
    option = new Option(CMD_CONTEXT, CMD_CONTEXT_LONG, true, "context for the HTTP servlet");
    option.setArgName("context");
    options.addOption(option);

    // kieker configuration file
    option = new Option(CMD_KIEKER_CONFIGURATION, CMD_KIEKER_CONFIGURATION_LONG, true,
            "kieker configuration file");
    option.setArgName("configuration");
    options.addOption(option);

    // mapping file for TCP and JMS
    option = new Option(CMD_MAP_FILE, CMD_MAP_FILE_LONG, true, "Class name to id (integer or string) mapping");
    option.setArgName("map-file");
    option.setType(File.class);
    option.setRequired(true);
    options.addOption(option);

    // libraries
    option = new Option(CMD_LIBRARIES, CMD_LIBRARIES_LONG, true,
            "List of library paths separated by " + File.pathSeparatorChar);
    option.setArgName("paths");
    option.setType(File.class);
    option.setRequired(true);
    option.setValueSeparator(File.pathSeparatorChar);
    options.addOption(option);

    // verbose
    option = new Option(CMD_VERBOSE, CMD_VERBOSE_LONG, true, "output processing information");
    option.setRequired(false);
    option.setOptionalArg(true);
    options.addOption(option);

    // statistics
    option = new Option(CMD_STATS, CMD_STATS_LONG, false, "output performance statistics");
    option.setRequired(false);
    options.addOption(option);

    // daemon mode
    option = new Option(CMD_DAEMON, CMD_DAEMON_LONG, false,
            "detach from console; TCP server allows multiple connections");
    option.setRequired(false);
    options.addOption(option);

    return options;
}

From source file:com.linkedin.helix.tools.ClusterStateVerifier.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();//from w w  w.  jav a  2 s  . com

    Option zkServerOption = OptionBuilder.withLongOpt(zkServerAddress)
            .withDescription("Provide zookeeper address").create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option timeoutOption = OptionBuilder.withLongOpt(timeout).withDescription("Timeout value for verification")
            .create();
    timeoutOption.setArgs(1);
    timeoutOption.setArgName("Timeout value (Optional), default=30s");

    Option sleepIntervalOption = OptionBuilder.withLongOpt(period)
            .withDescription("Polling period for verification").create();
    sleepIntervalOption.setArgs(1);
    sleepIntervalOption.setArgName("Polling period value (Optional), default=1s");

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(timeoutOption);
    options.addOption(sleepIntervalOption);

    return options;
}

From source file:com.netscape.cmstools.CRMFPopClient.java

public static Options createOptions() {

    Options options = new Options();

    Option option = new Option("d", true, "Security database location");
    option.setArgName("database");
    options.addOption(option);/*from  w  w w.  ja va 2s  .  com*/

    option = new Option("p", true, "Security token password");
    option.setArgName("password");
    options.addOption(option);

    option = new Option("h", true, "Security token name");
    option.setArgName("token");
    options.addOption(option);

    option = new Option("o", true, "Output file to store base-64 CRMF request");
    option.setArgName("output");
    options.addOption(option);

    option = new Option("n", true, "Subject DN");
    option.setArgName("subject DN");
    options.addOption(option);

    option = new Option("a", true, "Key algorithm");
    option.setArgName("algorithm");
    options.addOption(option);

    option = new Option("l", true, "Key length");
    option.setArgName("length");
    options.addOption(option);

    option = new Option("c", true, "ECC curve name");
    option.setArgName("curve");
    options.addOption(option);

    option = new Option("m", true, "CA server hostname and port");
    option.setArgName("hostname:port");
    options.addOption(option);

    option = new Option("f", true, "Certificate profile");
    option.setArgName("profile");
    options.addOption(option);

    option = new Option("u", true, "Username");
    option.setArgName("username");
    options.addOption(option);

    option = new Option("r", true, "Requestor");
    option.setArgName("requestor");
    options.addOption(option);

    option = new Option("q", true, "POP option");
    option.setArgName("POP option");
    options.addOption(option);

    option = new Option("b", true, "PEM transport certificate");
    option.setArgName("transport cert");
    options.addOption(option);

    option = new Option("k", true, "Attribute encoding");
    option.setArgName("boolean");
    options.addOption(option);

    option = new Option("x", true, "SSL certificate with ECDH ECDSA");
    option.setArgName("boolean");
    options.addOption(option);

    option = new Option("t", true, "Temporary");
    option.setArgName("boolean");
    options.addOption(option);

    option = new Option("s", true, "Sensitive");
    option.setArgName("sensitive");
    options.addOption(option);

    option = new Option("e", true, "Extractable");
    option.setArgName("extractable");
    options.addOption(option);

    option = new Option("w", true, "Algorithm to be used for key wrapping");
    option.setArgName("keywrap algorithm");
    options.addOption(option);

    options.addOption("y", false, "for Self-signed cmc.");

    options.addOption("v", "verbose", false, "Run in verbose mode.");
    options.addOption(null, "help", false, "Show help message.");

    return options;
}

From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java

public void addOption(String opt, String longOpt, String description, String argName) {
    Option option = new Option(opt, longOpt, true, description);
    option.setArgName(argName);
    add(opt, option);//ww  w.  ja v a  2 s  . c o m
}

From source file:com.netscape.cmstools.system.KRAConnectorRemoveCLI.java

public void createOptions() {
    Option option = new Option(null, "host", true, "KRA host");
    option.setArgName("host");
    options.addOption(option);/*from   w  w w  . j a v  a 2s. c o  m*/

    option = new Option(null, "port", true, "KRA port");
    option.setArgName("port");
    options.addOption(option);
}

From source file:com.netscape.cmstools.system.TPSConnectorAddCLI.java

public void createOptions() {
    Option option = new Option(null, "host", true, "TPS host");
    option.setArgName("host");
    options.addOption(option);/*from  w w  w. j  a  v a 2  s.c om*/

    option = new Option(null, "port", true, "TPS port");
    option.setArgName("port");
    options.addOption(option);
}

From source file:de.softwareforge.pgpsigner.commands.SignEventCommand.java

@Override
public Option getCommandLineOption() {
    Option option = super.getCommandLineOption();
    option.setArgs(1);/*from  www .java  2  s .c  o m*/
    option.setArgName("eventname");
    return option;
}

From source file:de.softwareforge.pgpsigner.commands.KeyServerCommand.java

@Override
public Option getCommandLineOption() {
    Option option = super.getCommandLineOption();
    option.setArgs(1);//  w ww  .ja v  a2  s  .co m
    option.setArgName("hostname");
    return option;
}

From source file:com.netscape.cmstools.system.TPSConnectorShowCLI.java

public void createOptions() {
    Option option = new Option(null, "host", true, "TPS host");
    option.setArgName("host");
    option.setRequired(true);/*from  w ww .  j a  v  a2 s .c  om*/
    options.addOption(option);

    option = new Option(null, "port", true, "TPS port");
    option.setArgName("port");
    options.addOption(option);
}