Example usage for org.apache.commons.cli OptionBuilder withArgName

List of usage examples for org.apache.commons.cli OptionBuilder withArgName

Introduction

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

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:eu.stratosphere.meteor.client.CLClient.java

@SuppressWarnings("static-access")
private void initOptions() {
    this.options.addOption(OptionBuilder.isRequired().withArgName("file").hasArg(true)
            .withDescription("Executes the given script").create("f"));
    this.options.addOption(OptionBuilder.withArgName("config").hasArg(true)
            .withDescription("Uses the given configuration").withLongOpt("configDir").create());
    this.options.addOption(OptionBuilder.withArgName("server").hasArg(true)
            .withDescription("Uses the specified server").withLongOpt("server").create());
    this.options.addOption(OptionBuilder.withArgName("port").hasArg(true)
            .withDescription("Uses the specified port").withLongOpt("port").create());
    this.options.addOption(OptionBuilder.withArgName("updateTime").hasArg(true)
            .withDescription("Checks with the given update time for the current status")
            .withLongOpt("updateTime").create());
    this.options.addOption(OptionBuilder.hasArg(false)
            .withDescription("Waits until the script terminates on the server").withLongOpt("wait").create());
}

From source file:fr.ens.transcriptome.teolenn.Main.java

/**
 * Create options for command line/*from w w  w  . ja  v  a2 s  .  co  m*/
 * @return an Options object
 */
private static Options makeOptions() {

    // create Options object
    final Options options = new Options();

    // add t option
    options.addOption("version", false, "show version of the software");
    options.addOption("about", false, "display information about this software");
    options.addOption("h", "help", false, "display this help");
    options.addOption("license", false, "display information about the license of this software");
    options.addOption("v", "verbose", false, "display external tools output");
    options.addOption("silent", false, "don't show log on console");

    options.addOption(OptionBuilder.withArgName("number").hasArg().withDescription("number of threads to use")
            .create("threads"));

    options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("configuration file to use")
            .create("conf"));

    options.addOption(
            OptionBuilder.withArgName("file").hasArg().withDescription("external log file").create("log"));

    options.addOption(
            OptionBuilder.withArgName("level").hasArg().withDescription("log level").create("loglevel"));

    return options;
}

From source file:dslistevents.DSListEvents.java

@SuppressWarnings("static-access")
// Method to process/parse the command line argument
private void processArgs(String[] args) {

    Options options = new Options();

    try {// ww w . j  a  va  2 s .  c  o  m
        // Make username a required option
        Option userName = OptionBuilder.withArgName("username").hasArg()
                .withDescription("Username to login as.").isRequired().create("u");

        // Make password a required option
        Option password = OptionBuilder.withArgName("password").hasArg().withDescription("User password")
                .isRequired().create("p");

        Option host = OptionBuilder.withArgName("host").hasArg().withDescription("DocuShare host").create("h");

        Option rmiPort = OptionBuilder.withArgName("rmiport").hasArg().withDescription("DS host RMI port")
                .create("port");

        Option domain = OptionBuilder.withArgName("domain").hasArg().withDescription("DocuShare domain")
                .create("d");

        options.addOption(userName);
        options.addOption(password);
        options.addOption(host);
        options.addOption(rmiPort);
        options.addOption(domain);

        // Parse the command line
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        // Check options
        if (cmd.hasOption("u")) {
            this.userName = cmd.getOptionValue("u");
        }
        if (cmd.hasOption("p")) {
            this.password = cmd.getOptionValue("p");
        }
        if (cmd.hasOption("h")) {
            this.host = cmd.getOptionValue("h");
        }
        if (cmd.hasOption("port")) {
            this.rmiPort = Integer.parseInt(cmd.getOptionValue("port"));
        }
        if (cmd.hasOption("d")) {
            this.domain = cmd.getOptionValue("d");
        }

    } catch (NumberFormatException e) {
        System.out.println("The RMI port must be an integer.");
        System.exit(-1);
    } catch (Exception e) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(progName, options, true);
        // e.printStackTrace();
        System.exit(-1);
    }
}

From source file:ivory.app.BuildIndex.java

@SuppressWarnings({ "static-access" })
@Override/*from  w  ww.j  av  a  2  s  .c o m*/
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(new Option(POSITIONAL_INDEX_IP, "build positional index (IP algorithm)"));
    options.addOption(new Option(POSITIONAL_INDEX_LP, "build positional index (LP algorithm)"));
    options.addOption(new Option(NONPOSITIONAL_INDEX_IP, "build nonpositional index (IP algorithm)"));

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) index path")
            .create(INDEX_PATH));
    options.addOption(OptionBuilder.withArgName("num").hasArg()
            .withDescription("(optional) number of index partitions: 64 default").create(INDEX_PARTITIONS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INDEX_PATH)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String indexPath = cmdline.getOptionValue(INDEX_PATH);

    int indexPartitions = cmdline.hasOption(INDEX_PARTITIONS)
            ? Integer.parseInt(cmdline.getOptionValue(INDEX_PARTITIONS))
            : 64;

    Configuration conf = getConf();

    LOG.info("Tool name: " + this.getClass().getSimpleName());
    LOG.info(String.format(" -%s %s", INDEX_PATH, indexPath));
    LOG.info(String.format(" -%s %d", INDEX_PARTITIONS, indexPartitions));

    if (cmdline.hasOption(POSITIONAL_INDEX_IP)) {
        LOG.info(String.format(" -%s", POSITIONAL_INDEX_IP));
        conf.set(Constants.IndexPath, indexPath);
        conf.setInt(Constants.NumReduceTasks, indexPartitions);
        conf.set(Constants.PostingsListsType,
                ivory.core.data.index.PostingsListDocSortedPositional.class.getCanonicalName());

        new BuildIPInvertedIndexDocSorted(conf).run();
        new BuildIntPostingsForwardIndex(conf).run();
    } else if (cmdline.hasOption(POSITIONAL_INDEX_LP)) {
        LOG.info(String.format(" -%s", POSITIONAL_INDEX_LP));
        conf.set(Constants.IndexPath, indexPath);
        conf.setInt(Constants.NumReduceTasks, indexPartitions);
        conf.set(Constants.PostingsListsType,
                ivory.core.data.index.PostingsListDocSortedPositional.class.getCanonicalName());

        conf.setFloat("Ivory.IndexingMapMemoryThreshold", 0.9f);
        conf.setFloat("Ivory.IndexingReduceMemoryThreshold", 0.9f);
        conf.setInt("Ivory.MaxHeap", 2048);
        conf.setInt("Ivory.MaxNDocsBeforeFlush", 50000);

        new BuildLPInvertedIndexDocSorted(conf).run();
        new BuildIntPostingsForwardIndex(conf).run();
    } else if (cmdline.hasOption(NONPOSITIONAL_INDEX_IP)) {
        LOG.info(String.format(" -%s", NONPOSITIONAL_INDEX_IP));
        conf.set(Constants.IndexPath, indexPath);
        conf.setInt(Constants.NumReduceTasks, indexPartitions);
        conf.set(Constants.PostingsListsType,
                ivory.core.data.index.PostingsListDocSortedNonPositional.class.getCanonicalName());

        new BuildIPInvertedIndexDocSorted(conf).run();
        new BuildIntPostingsForwardIndex(conf).run();
    } else {
        LOG.info(String.format("Nothing to do. Specify one of the following: %s, %s, %s", POSITIONAL_INDEX_IP,
                POSITIONAL_INDEX_LP, NONPOSITIONAL_INDEX_IP));
    }

    return 0;
}

From source file:de.clusteval.data.dataset.generator.CassiniDataSetGenerator.java

@Override
protected Options getOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("n");
    OptionBuilder.isRequired();//  ww  w . ja  va 2  s .  c om
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of points.");
    Option option = OptionBuilder.create("n");
    options.addOption(option);

    return options;
}

From source file:addimg2db.AddImgCommandLine.java

boolean parseCommand(String[] args, String programName, String version) {
    ret = true;//  w ww.  j  a  va2  s  . co m

    Options options = new Options();

    options.addOption(new Option("help", "print this message"));
    options.addOption(new Option("version", "print the version information and exit"));
    options.addOption(new Option("verbose", "print information on what we're doing"));
    options.addOption(new Option("debug", "be very verbose"));

    options.addOption(
            new Option("auto", "if file name ends with <gpstime>-<duration><unit> append to description "));

    options.addOption(OptionBuilder.withArgName("user").hasArg()
            .withDescription("user name for addition [default=\"system\"]").create("user"));
    options.addOption(OptionBuilder.withArgName("group").hasArg()
            .withDescription("group name [default=no group]").create("group"));
    options.addOption(OptionBuilder.withArgName("desc").hasArg()
            .withDescription("description saved with image [default=empty]").create("desc"));

    CommandLineParser parser = new GnuParser();

    wantHelp = false;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Command parsing failed.  Reason: " + exp.getMessage());
        wantHelp = true;
        line = null;
    }
    if (line != null) {
        if (line.hasOption("version")) {
            System.out.println(programName + " - version " + version);
            ret = false;
        }

        wantHelp = line.hasOption("help");
        auto = line.hasOption("auto");
        verbose = line.hasOption("verbose");

        user = "system";
        if (line.hasOption("user")) {
            user = line.getOptionValue("user");
        }

        group = "";
        if (line.hasOption("group")) {
            group = line.getOptionValue("group");
        }

        description = "";
        if (line.hasOption("desc")) {
            description = line.getOptionValue("desc");
        }

        files = line.getArgs();

        if (line.hasOption("debug")) {
            System.out.format("auto:  %1$b%n", auto);
            System.out.format("desc:  %1$s%n", description);
            System.out.format("group: %1$s%n", group);
            System.out.format("user:  %1$s%n", user);
            for (String file : files) {
                System.out.format("file:  %1$s%n", file);
            }
        }

    }
    if (files == null || files.length == 0) {
        ermsg += "No input files specified.\n";
    }

    if (!ermsg.isEmpty()) {
        System.out.println("Command error:\n" + ermsg);
        wantHelp = true;
        ret = false;
    }
    if (wantHelp) {
        HelpFormatter formatter = new HelpFormatter();
        String syntax = "java -jar " + programName + ".jar [options] imageFilePath...";
        formatter.printHelp(syntax, options);
        ret = false;
    }

    return ret;
}

From source file:de.clusteval.data.dataset.generator.CircleDataSetGenerator.java

@Override
protected Options getOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("n");
    OptionBuilder.isRequired();/*  ww w  .  j  a v a  2  s .  com*/
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of points.");
    Option option = OptionBuilder.create("n");
    options.addOption(option);

    OptionBuilder.withArgName("d");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of dimensions.");
    option = OptionBuilder.create("d");
    options.addOption(option);

    return options;
}

From source file:jlite.cli.JobMatch.java

private static Options setupOptions() {
    Options options = new Options();

    options.addOption(OptionBuilder.withDescription("displays usage").create("help"));

    options.addOption(OptionBuilder.withArgName("id_string")
            .withDescription("delegation id (default is user name)").hasArg().create("d"));

    options.addOption(OptionBuilder.withDescription("automatic proxy delegation").create("a"));

    options.addOption(OptionBuilder.withArgName("service_URL").withDescription("WMProxy service endpoint")
            .hasArg().create("e"));

    options.addOption(OptionBuilder.withArgName("proxyfile")
            .withDescription("non-standard location of proxy cert").hasArg().create("proxypath"));

    options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml"));

    return options;
}

From source file:com.haulmont.cuba.core.sys.utils.DbUpdaterUtil.java

@SuppressWarnings("AccessStaticViaInstance")
public void execute(String[] args) {
    Options cliOptions = new Options();

    Option dbConnectionOption = OptionBuilder.withArgName("connectionString").hasArgs()
            .withDescription("JDBC Database URL").isRequired().create("dbUrl");

    Option dbUserOption = OptionBuilder.withArgName("userName").hasArgs().withDescription("Database user")
            .isRequired().create("dbUser");

    Option dbPasswordOption = OptionBuilder.withArgName("password").hasArgs()
            .withDescription("Database password").isRequired().create("dbPassword");

    Option dbDriverClassOption = OptionBuilder.withArgName("driverClassName").hasArgs()
            .withDescription("JDBC driver class name").create("dbDriver");

    Option dbDirOption = OptionBuilder.withArgName("filePath").hasArgs()
            .withDescription("Database scripts directory").isRequired().create("scriptsDir");

    Option dbTypeOption = OptionBuilder.withArgName("dbType").hasArgs()
            .withDescription("DBMS type: postgres|mssql|oracle|etc").isRequired().create("dbType");

    Option dbVersionOption = OptionBuilder.withArgName("dbVersion").hasArgs()
            .withDescription("DBMS version: 2012|etc").create("dbVersion");

    Option dbExecuteGroovyOption = OptionBuilder.withArgName("executeGroovy").hasArgs()
            .withDescription("Ignoring Groovy scripts").create("executeGroovy");

    Option showUpdatesOption = OptionBuilder.withDescription("Print update scripts").create("check");

    Option applyUpdatesOption = OptionBuilder.withDescription("Update database").create("update");

    Option createDbOption = OptionBuilder.withDescription("Create database").create("create");

    cliOptions.addOption("help", false, "Print help");
    cliOptions.addOption(dbConnectionOption);
    cliOptions.addOption(dbUserOption);//w  w  w  .  j ava 2s.  c o  m
    cliOptions.addOption(dbPasswordOption);
    cliOptions.addOption(dbDirOption);
    cliOptions.addOption(dbTypeOption);
    cliOptions.addOption(dbVersionOption);
    cliOptions.addOption(dbExecuteGroovyOption);
    cliOptions.addOption(showUpdatesOption);
    cliOptions.addOption(applyUpdatesOption);
    cliOptions.addOption(createDbOption);

    CommandLineParser parser = new PosixParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;
    try {
        cmd = parser.parse(cliOptions, args);
    } catch (ParseException exp) {
        formatter.printHelp("dbupdate", cliOptions);
        return;
    }

    if (cmd.hasOption("help") || (!cmd.hasOption(showUpdatesOption.getOpt()))
            && !cmd.hasOption(applyUpdatesOption.getOpt()) && !cmd.hasOption(createDbOption.getOpt()))
        formatter.printHelp("dbupdate", cliOptions);
    else {
        this.dbScriptsDirectory = cmd.getOptionValue(dbDirOption.getOpt());
        File directory = new File(dbScriptsDirectory);
        if (!directory.exists()) {
            log.error("Not found db update directory");
            return;
        }

        dbmsType = cmd.getOptionValue(dbTypeOption.getOpt());
        dbmsVersion = StringUtils.trimToEmpty(cmd.getOptionValue(dbVersionOption.getOpt()));

        AppContext.Internals.setAppComponents(new AppComponents("core"));

        AppContext.setProperty("cuba.dbmsType", dbmsType);
        AppContext.setProperty("cuba.dbmsVersion", dbmsVersion);

        String dbDriver;
        if (!cmd.hasOption(dbDriverClassOption.getOpt())) {
            switch (dbmsType) {
            case "postgres":
                dbDriver = "org.postgresql.Driver";
                break;
            case "mssql":
                if (MS_SQL_2005.equals(dbmsVersion)) {
                    dbDriver = "net.sourceforge.jtds.jdbc.Driver";
                } else {
                    dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
                }
                break;
            case "oracle":
                dbDriver = "oracle.jdbc.OracleDriver";
                break;
            default:
                log.error(
                        "Unable to determine driver class name by DBMS type. Please provide driverClassName option");
                return;
            }
        } else {
            dbDriver = cmd.getOptionValue(dbDriverClassOption.getOpt());
        }

        try {
            Class.forName(dbDriver);
        } catch (ClassNotFoundException e) {
            log.error("Unable to load driver class " + dbDriver);
            return;
        }

        String connectionStringParam = cmd.getOptionValue(dbConnectionOption.getOpt());
        try {
            this.dataSource = new SingleConnectionDataSource(connectionStringParam,
                    cmd.getOptionValue(dbUserOption.getOpt()), cmd.getOptionValue(dbPasswordOption.getOpt()));
        } catch (SQLException e) {
            log.error("Unable to connect to db: " + connectionStringParam);
            return;
        }

        if (cmd.hasOption(createDbOption.getOpt())) {
            // create database from init scripts
            StringBuilder availableScripts = new StringBuilder();
            for (ScriptResource initScript : getInitScripts()) {
                availableScripts.append("\t").append(getScriptName(initScript)).append("\n");
            }
            log.info("Available create scripts: \n" + availableScripts);
            log.info(String.format("Do you want to create database %s ? [y/n]", connectionStringParam));
            Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
            if ("y".equals(scanner.next())) {
                doInit();
            }
        } else {
            boolean updatesAvailable = false;
            try {
                List<String> scripts;

                executeGroovy = !(cmd.hasOption(dbExecuteGroovyOption.getOpt())
                        && cmd.getOptionValue(dbExecuteGroovyOption.getOpt()).equals("false"));

                scripts = findUpdateDatabaseScripts();

                if (!scripts.isEmpty()) {
                    StringBuilder availableScripts = new StringBuilder();
                    for (String script : scripts) {
                        availableScripts.append("\t").append(script).append("\n");
                    }
                    log.info("Available updates:\n" + availableScripts);
                    updatesAvailable = true;
                } else
                    log.info("No available updates found for database");
            } catch (DbInitializationException e) {
                log.warn("Database not initialized");
                return;
            }

            if (updatesAvailable && cmd.hasOption(applyUpdatesOption.getOpt())) {
                log.info(String.format("Do you want to apply updates to %s ? [y/n]", connectionStringParam));
                Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
                if ("y".equals(scanner.next())) {
                    doUpdate();
                }
            }
        }
    }
}

From source file:com.boundary.sdk.snmp.metric.ExportMibCli.java

@SuppressWarnings("static-access")
private void buildOptions() {
    helpOption = OptionBuilder.withDescription("Display help information").withLongOpt("help").create("?");

    licenseOption = OptionBuilder.withArgName("license").hasArgs().withValueSeparator(' ').withDescription(
            "The license key string you received with the purchase a SNMP4J-SMI license or its evaluation."
                    + "You may provide leave empty, but then you may not use any MIB modules of the \"enterprise\" OID subtree.")
            .withLongOpt("license").create("l");

    repoDirOption = OptionBuilder.withArgName("repository_dir").hasArg().isRequired()
            .withDescription("Directory where the " + commandName + " can read compiled MIB modules.")
            .withLongOpt("repository-dir").create("r");

    verboseOption = OptionBuilder.withDescription("Verbose mode, provide additional debug output.")
            .withLongOpt("verbose").create("v");

    exportOption = OptionBuilder.withArgName("type").hasArgs(1)
            .withDescription("Selects what to export which is either: METRIC,OID, or OUT. Defaults to METRIC.")
            .withLongOpt("export").create("e");

    mibOption = OptionBuilder.withArgName("mib_name").hasArgs().isRequired().withValueSeparator(',')
            .withDescription("List of MIB(s) to export. Example: SNMPv2-MIB").withLongOpt("mib").create("m");

    options.addOption(helpOption);/*from w  w w  .j av  a  2  s .  c om*/
    options.addOption(verboseOption);
    options.addOption(licenseOption);
    options.addOption(repoDirOption);
    options.addOption(exportOption);
    options.addOption(mibOption);

}