Search in sources :

Example 11 with PosixParser

use of org.apache.commons.cli.PosixParser in project hbase by apache.

the class DataBlockEncodingTool method main.

/**
   * A command line interface to benchmarks. Parses command-line arguments and
   * runs the appropriate benchmarks.
   * @param args Should have length at least 1 and holds the file path to HFile.
   * @throws IOException If you specified the wrong file.
   */
public static void main(final String[] args) throws IOException {
    // set up user arguments
    Options options = new Options();
    options.addOption(OPT_HFILE_NAME, true, "HFile to analyse (REQUIRED)");
    options.getOption(OPT_HFILE_NAME).setArgName("FILENAME");
    options.addOption(OPT_KV_LIMIT, true, "Maximum number of KeyValues to process. A benchmark stops running " + "after iterating over this many KV pairs.");
    options.getOption(OPT_KV_LIMIT).setArgName("NUMBER");
    options.addOption(OPT_MEASURE_THROUGHPUT, false, "Measure read throughput");
    options.addOption(OPT_OMIT_CORRECTNESS_TEST, false, "Omit corectness tests.");
    options.addOption(OPT_ENCODING_ALGORITHM, true, "What kind of compression algorithm use for comparison.");
    options.addOption(OPT_BENCHMARK_N_TIMES, true, "Number of times to run each benchmark. Default value: " + DEFAULT_BENCHMARK_N_TIMES);
    options.addOption(OPT_BENCHMARK_N_OMIT, true, "Number of first runs of every benchmark to exclude from " + "statistics (" + DEFAULT_BENCHMARK_N_OMIT + " by default, so that " + "only the last " + (DEFAULT_BENCHMARK_N_TIMES - DEFAULT_BENCHMARK_N_OMIT) + " times are included in statistics.)");
    // parse arguments
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Could not parse arguments!");
        System.exit(-1);
        // avoid warning
        return;
    }
    int kvLimit = Integer.MAX_VALUE;
    if (cmd.hasOption(OPT_KV_LIMIT)) {
        kvLimit = Integer.parseInt(cmd.getOptionValue(OPT_KV_LIMIT));
    }
    // basic argument sanity checks
    if (!cmd.hasOption(OPT_HFILE_NAME)) {
        LOG.error("Please specify HFile name using the " + OPT_HFILE_NAME + " option");
        printUsage(options);
        System.exit(-1);
    }
    String pathName = cmd.getOptionValue(OPT_HFILE_NAME);
    String compressionName = DEFAULT_COMPRESSION.getName();
    if (cmd.hasOption(OPT_ENCODING_ALGORITHM)) {
        compressionName = cmd.getOptionValue(OPT_ENCODING_ALGORITHM).toLowerCase(Locale.ROOT);
    }
    boolean doBenchmark = cmd.hasOption(OPT_MEASURE_THROUGHPUT);
    boolean doVerify = !cmd.hasOption(OPT_OMIT_CORRECTNESS_TEST);
    if (cmd.hasOption(OPT_BENCHMARK_N_TIMES)) {
        benchmarkNTimes = Integer.valueOf(cmd.getOptionValue(OPT_BENCHMARK_N_TIMES));
    }
    if (cmd.hasOption(OPT_BENCHMARK_N_OMIT)) {
        benchmarkNOmit = Integer.valueOf(cmd.getOptionValue(OPT_BENCHMARK_N_OMIT));
    }
    if (benchmarkNTimes < benchmarkNOmit) {
        LOG.error("The number of times to run each benchmark (" + benchmarkNTimes + ") must be greater than the number of benchmark runs to exclude " + "from statistics (" + benchmarkNOmit + ")");
        System.exit(1);
    }
    LOG.info("Running benchmark " + benchmarkNTimes + " times. " + "Excluding the first " + benchmarkNOmit + " times from statistics.");
    final Configuration conf = HBaseConfiguration.create();
    try {
        testCodecs(conf, kvLimit, pathName, compressionName, doBenchmark, doVerify);
    } finally {
        (new CacheConfig(conf)).getBlockCache().shutdown();
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig)

Example 12 with PosixParser

use of org.apache.commons.cli.PosixParser in project zookeeper by apache.

the class SyncCommand method parse.

@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }
    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }
    return this;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) ParseException(org.apache.commons.cli.ParseException) Parser(org.apache.commons.cli.Parser) PosixParser(org.apache.commons.cli.PosixParser)

Example 13 with PosixParser

use of org.apache.commons.cli.PosixParser in project zookeeper by apache.

the class AddAuthCommand method parse.

@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }
    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }
    return this;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) ParseException(org.apache.commons.cli.ParseException) Parser(org.apache.commons.cli.Parser) PosixParser(org.apache.commons.cli.PosixParser)

Example 14 with PosixParser

use of org.apache.commons.cli.PosixParser in project Apktool by iBotPeaches.

the class Main method main.

public static void main(String[] args) throws IOException, InterruptedException, BrutException {
    // set verbosity default
    Verbosity verbosity = Verbosity.NORMAL;
    // cli parser
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine;
    // load options
    _Options();
    try {
        commandLine = parser.parse(allOptions, args, false);
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        usage();
        return;
    }
    // check for verbose / quiet
    if (commandLine.hasOption("-v") || commandLine.hasOption("--verbose")) {
        verbosity = Verbosity.VERBOSE;
    } else if (commandLine.hasOption("-q") || commandLine.hasOption("--quiet")) {
        verbosity = Verbosity.QUIET;
    }
    setupLogging(verbosity);
    // check for advance mode
    if (commandLine.hasOption("advance") || commandLine.hasOption("advanced")) {
        setAdvanceMode(true);
    }
    // @todo use new ability of apache-commons-cli to check hasOption for non-prefixed items
    boolean cmdFound = false;
    for (String opt : commandLine.getArgs()) {
        if (opt.equalsIgnoreCase("d") || opt.equalsIgnoreCase("decode")) {
            cmdDecode(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("b") || opt.equalsIgnoreCase("build")) {
            cmdBuild(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) {
            cmdInstallFramework(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("empty-framework-dir")) {
            cmdEmptyFrameworkDirectory(commandLine);
            cmdFound = true;
        } else if (opt.equalsIgnoreCase("publicize-resources")) {
            cmdPublicizeResources(commandLine);
            cmdFound = true;
        }
    }
    // if no commands ran, run the version / usage check.
    if (cmdFound == false) {
        if (commandLine.hasOption("version")) {
            _version();
        } else {
            usage();
        }
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 15 with PosixParser

use of org.apache.commons.cli.PosixParser in project head by mifos.

the class PPITestDataGenerator method parseOptions.

public void parseOptions(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        if (line.hasOption(HELP_OPTION_NAME)) {
            showHelp(options);
            System.exit(0);
        }
        if (line.hasOption(TEST_DATA_FILE_OPTION_NAME)) {
            if (line.hasOption(TEST_DATA_DIRECTORY_OPTION_NAME)) {
                fail("Specify either a data set (-f) or data directory (-a) but not both.");
            }
            dataSetName = line.getOptionValue(TEST_DATA_FILE_OPTION_NAME);
        } else if (line.hasOption(TEST_DATA_DIRECTORY_OPTION_NAME)) {
            testDataDirectoryName = line.getOptionValue(TEST_DATA_DIRECTORY_OPTION_NAME);
        } else {
            fail("Specify either a data set (-f) or data directory (-a)");
        }
        if (line.hasOption(CLIENT_GLOBAL_ID_OPTION_NAME)) {
            clientGlobalId = line.getOptionValue(CLIENT_GLOBAL_ID_OPTION_NAME);
        } else {
            missingOption(clientGlobalIdOption);
        }
    } catch (ParseException exp) {
        fail("Parsing failed.  Reason: " + exp.getMessage());
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Aggregations

PosixParser (org.apache.commons.cli.PosixParser)79 CommandLine (org.apache.commons.cli.CommandLine)74 CommandLineParser (org.apache.commons.cli.CommandLineParser)61 Options (org.apache.commons.cli.Options)52 ParseException (org.apache.commons.cli.ParseException)50 IOException (java.io.IOException)19 File (java.io.File)17 HelpFormatter (org.apache.commons.cli.HelpFormatter)13 SystemExitException (org.apache.openejb.cli.SystemExitException)7 Properties (java.util.Properties)6 Parser (org.apache.commons.cli.Parser)6 List (java.util.List)5 Option (org.apache.commons.cli.Option)5 Path (org.apache.hadoop.fs.Path)4 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 InitialContext (javax.naming.InitialContext)3 NamingException (javax.naming.NamingException)3 ServiceUnavailableException (javax.naming.ServiceUnavailableException)3 Configuration (org.apache.hadoop.conf.Configuration)3