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

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

Introduction

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

Prototype

public static OptionBuilder hasArg() 

Source Link

Document

The next Option created will require an argument value.

Usage

From source file:org.apache.hive.hplsql.Arguments.java

@SuppressWarnings("static-access")
Arguments() {//from   w  w w. j av  a 2s . c  om
    // -e 'query'
    options.addOption(OptionBuilder.hasArg().withArgName("quoted-query-string")
            .withDescription("HPL/SQL from command line").create('e'));

    // -f <file>
    options.addOption(
            OptionBuilder.hasArg().withArgName("filename").withDescription("HPL/SQL from a file").create('f'));

    // -main entry_point_name
    options.addOption(OptionBuilder.hasArg().withArgName("procname")
            .withDescription("Entry point (procedure or function name)").create("main"));

    // -hiveconf x=y
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("property=value")
            .withLongOpt("hiveconf").withDescription("Value for given property").create());

    // Substitution option -d, --define
    options.addOption(
            OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value").withLongOpt("define")
                    .withDescription("Variable substitution e.g. -d A=B or --define A=B").create('d'));

    // Substitution option --hivevar
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value")
            .withLongOpt("hivevar").withDescription("Variable substitution e.g. --hivevar A=B").create());

    // [-version|--version]
    options.addOption(new Option("version", "version", false, "Print HPL/SQL version"));

    // [-trace|--trace]
    options.addOption(new Option("trace", "trace", false, "Print debug information"));

    // [-offline|--offline]
    options.addOption(new Option("offline", "offline", false, "Offline mode - skip SQL execution"));

    // [-H|--help]
    options.addOption(new Option("H", "help", false, "Print help information"));
}

From source file:org.apache.hive.jdbc.beeline.OptionsProcessor.java

@SuppressWarnings("static-access")
public OptionsProcessor() {

    // -database database
    options.addOption(OptionBuilder.hasArg().withArgName("databasename").withLongOpt("database")
            .withDescription("Specify the database to use").create());

    // -e 'quoted-query-string'
    options.addOption(OptionBuilder.hasArg().withArgName("quoted-query-string")
            .withDescription("SQL from command line").create('e'));

    // -f <query-file>
    options.addOption(/*from   ww  w.j av  a 2 s  . com*/
            OptionBuilder.hasArg().withArgName("filename").withDescription("SQL from files").create('f'));

    // -hiveconf x=y
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("property=value")
            .withLongOpt("hiveconf").withDescription("Use value for given property").create());

    // -sessVar x=y
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("property=value")
            .withLongOpt("sessVar").withDescription("Use value for given property").create());

    // -h hostname/ippaddress
    options.addOption(OptionBuilder.hasArg().withArgName("hostname")
            .withDescription("connecting to Hive Server on remote host").create('h'));

    // -p port
    options.addOption(OptionBuilder.hasArg().withArgName("port")
            .withDescription("connecting to Hive Server on port number").create('p'));

    // Substitution option -d, --define
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value")
            .withLongOpt("define")
            .withDescription("Variable subsitution to apply to hive commands. e.g. -d A=B or --define A=B")
            .create('d'));

    // Substitution option --hivevar
    options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value")
            .withLongOpt("hivevar")
            .withDescription("Variable subsitution to apply to hive commands. e.g. --hivevar A=B").create());

    // [-S|--silent]
    options.addOption(new Option("S", "silent", false, "Silent mode in interactive shell"));

    // [-v|--verbose]
    options.addOption(new Option("v", "verbose", false, "Verbose mode (echo executed SQL to the console)"));

    // [-H|--help]
    options.addOption(new Option("H", "help", false, "Print help information"));
}

From source file:org.apache.impala.infra.tableflattener.Main.java

@SuppressWarnings("static-access")
void parseArgs(String[] args) throws ParseException, IOException {
    cliOptions_ = new Options();
    cliOptions_.addOption(OptionBuilder.withLongOpt("help").create("h"));
    cliOptions_.addOption(OptionBuilder.hasArg().withLongOpt("input-data-format")
            .withDescription("The format of the input file. Ex, avro").create("f"));
    cliOptions_.addOption(OptionBuilder.hasArg().withLongOpt("input-data-compression")
            .withDescription("The compression type of the input file. Ex, snappy").create("c"));
    cliOptions_.addOption(OptionBuilder.hasArg().withLongOpt("input-schema-uri")
            .withDescription("The URI of the input file's schema. Ex, file://foo.avsc").create("s"));
    CommandLineParser parser = new PosixParser();
    commandLine_ = parser.parse(cliOptions_, args);

    if (commandLine_.hasOption("h"))
        printHelp();//  ww w  .ja v  a  2 s .  co  m

    DatasetDescriptor.Builder datasetDescrBuilder = new DatasetDescriptor.Builder();

    String[] dataArgs = commandLine_.getArgs();
    if (dataArgs.length != 2) {
        printHelp("Exactly two arguments are required");
    }

    URI dataFile = URI.create(dataArgs[0]);
    outputDir_ = URI.create(dataArgs[1]);
    datasetDescrBuilder.location(dataFile);

    Format inputFormat;
    if (commandLine_.hasOption("f")) {
        inputFormat = Formats.fromString(commandLine_.getOptionValue("f"));
    } else {
        String dataFilePath = dataFile.getPath();
        if (dataFilePath == null || dataFilePath.isEmpty()) {
            printHelp("Data file URI is missing a path component: " + dataFile.toString());
        }
        String ext = FilenameUtils.getExtension(dataFilePath);
        if (ext.isEmpty()) {
            printHelp("The file format (-f) must be specified");
        }
        inputFormat = Formats.fromString(ext);
    }
    datasetDescrBuilder.format(inputFormat);

    if (commandLine_.hasOption("c")) {
        datasetDescrBuilder.compressionType(CompressionType.forName(commandLine_.getOptionValue("c")));
    }

    if (commandLine_.hasOption("s")) {
        datasetDescrBuilder.schemaUri(commandLine_.getOptionValue("s"));
    } else if (inputFormat == Formats.AVRO) {
        datasetDescrBuilder.schemaFromAvroDataFile(dataFile);
    } else if (inputFormat == Formats.PARQUET) {
        ParquetMetadata parquetMetadata = ParquetFileReader.readFooter(new Configuration(),
                new org.apache.hadoop.fs.Path(dataFile));
        datasetDescrBuilder
                .schema(new AvroSchemaConverter().convert(parquetMetadata.getFileMetaData().getSchema()));
    } else {
        printHelp("A schema (-s) is required for data format " + inputFormat.getName());
    }

    datasetDescr_ = datasetDescrBuilder.build();
}

From source file:org.apache.isis.core.webserver.internal.OptionHandlerPort.java

@Override
@SuppressWarnings("static-access")
public void addOption(final Options options) {
    OptionBuilder.withArgName("port");
    final Option option = OptionBuilder.hasArg().withLongOpt(OptionHandlerPort.PORT_LONG_OPT)
            .withDescription("port to listen on").create(OptionHandlerPort.PORT_OPT);
    options.addOption(option);/*from   ww  w .  j  a  va  2 s  .  c  om*/
}

From source file:org.apache.james.jspf.impl.SPFQuery.java

/**
 * Return the generated Options/*www .ja v  a  2  s  .  com*/
 * 
 * @return options
 */
private static Options generateOptions() {
    Options options = new Options();

    OptionBuilder.withLongOpt(CMD_IP);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withArgName("ip");
    OptionBuilder.withDescription("Sender IP address");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_IP));

    OptionBuilder.withLongOpt(CMD_SENDER);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withArgName("sender");
    OptionBuilder.withDescription("Sender address");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_SENDER));

    OptionBuilder.withLongOpt(CMD_HELO);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withArgName("helo");
    OptionBuilder.withDescription("Helo name");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_HELO));

    OptionBuilder.withLongOpt(CMD_DEFAULT_EXP);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withArgName("expl");
    OptionBuilder.withDescription("Default explanation");
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_DEFAULT_EXP));

    OptionBuilder.withLongOpt(CMD_BEST_GUESS);
    OptionBuilder.withArgName("bestguess");
    OptionBuilder.withDescription("Enable 'best guess' rule");
    options.addOption(OptionBuilder.create(CHAR_BEST_GUESS));

    OptionBuilder.withLongOpt(CMD_TRUSTED_FORWARDER);
    OptionBuilder.withArgName("trustedfwd");
    OptionBuilder.withDescription("Enable 'trusted forwarder' rule");
    options.addOption(OptionBuilder.create(CHAR_TRUSTED_FORWARDER));

    OptionBuilder.withLongOpt(CMD_DEBUG);
    OptionBuilder.withArgName("debug");
    OptionBuilder.withDescription("Enable debug");
    options.addOption(OptionBuilder.create(CHAR_DEBUG));

    OptionBuilder.withLongOpt(CMD_VERBOSE);
    OptionBuilder.withArgName("verbose");
    OptionBuilder.withDescription("Enable verbose mode");
    options.addOption(OptionBuilder.create(CHAR_VERBOSE));

    return options;
}

From source file:org.apache.james.jspf.tester.DNSTestingServerLauncher.java

/**
 * Return the generated Options//w w  w  .j  a  va  2  s  . c  om
 * 
 * @return options
 */
private static Options generateOptions() {
    Options options = new Options();

    OptionBuilder.withLongOpt(CMD_IP);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("ip");
    OptionBuilder.withDescription("Listening IP (default: 0.0.0.0 for every IP)");
    options.addOption(OptionBuilder.create(CHAR_IP));

    OptionBuilder.withLongOpt(CMD_PORT);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("port");
    OptionBuilder.withDescription("Listening port (default: 53)");
    options.addOption(OptionBuilder.create(CHAR_PORT));

    OptionBuilder.withLongOpt(CMD_FILE);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withDescription("YML file name");
    OptionBuilder.withArgName("file");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_FILE));

    OptionBuilder.withLongOpt(CMD_TESTNAME);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Test name");
    OptionBuilder.withArgName("test");
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(CHAR_TESTNAME));

    return options;
}

From source file:org.apache.kylin.source.hive.BeelineOptionsProcessor.java

public BeelineOptionsProcessor() {

    options.addOption(OptionBuilder.hasArg().withArgName("url").create('u'));
    options.addOption(OptionBuilder.hasArg().withArgName("username").create('n'));
    options.addOption(OptionBuilder.hasArg().withArgName("password").create('p'));

}

From source file:org.apache.nutch.api.NutchServer.java

private static Options createOptions() {
    Options options = new Options();
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("logging level");
    OptionBuilder.withDescription("Select a logging level for the NutchServer: \n"
            + "ALL|CONFIG|FINER|FINEST|INFO|OFF|SEVERE|WARNING");
    options.addOption(OptionBuilder.create(CMD_LOG_LEVEL));

    OptionBuilder.withDescription("Stop running NutchServer. "
            + "true value forces the Server to stop despite running jobs e.g. kills the tasks ");
    OptionBuilder.hasOptionalArg();//  ww  w.  j  a v  a 2 s. c o  m
    OptionBuilder.withArgName("force");
    options.addOption(OptionBuilder.create(CMD_STOP));

    OptionBuilder.withDescription("Show this help");
    options.addOption(OptionBuilder.create(CMD_HELP));

    OptionBuilder.withDescription("Port to use for restful API.");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withArgName("port number");
    options.addOption(OptionBuilder.create(CMD_PORT));
    return options;
}

From source file:org.apache.nutch.scoring.webgraph.LinkDumper.java

/**
 * Runs the LinkDumper tool. This simply creates the database, to read the
 * values the nested Reader tool must be used.
 *///from  ww  w  . j a  v  a2s  . co  m
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the web graph database to use");
    Option webGraphDbOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webGraphDbOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("LinkDumper", options);
            return -1;
        }

        String webGraphDb = line.getOptionValue("webgraphdb");
        dumpLinks(new Path(webGraphDb));
        return 0;
    } catch (Exception e) {
        LOG.error("LinkDumper: " + StringUtils.stringifyException(e));
        return -2;
    }
}

From source file:org.apache.nutch.scoring.webgraph.LinkRank.java

/**
 * Runs the LinkRank tool./*from   www. jav  a2s .c o m*/
 */
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the web graph db to use");
    Option webgraphOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webgraphOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("LinkRank", options);
            return -1;
        }

        String webGraphDb = line.getOptionValue("webgraphdb");

        analyze(new Path(webGraphDb));
        return 0;
    } catch (Exception e) {
        LOG.error("LinkAnalysis: " + StringUtils.stringifyException(e));
        return -2;
    }
}