Search in sources :

Example 1 with ParseException

use of org.apache.commons.cli.ParseException in project hive by apache.

the class HBaseSchemaTool method main.

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("help").withDescription("You're looking at it").create('h'));
    options.addOption(OptionBuilder.withLongOpt("install").withDescription("Install the schema onto an HBase cluster.").create('i'));
    options.addOption(OptionBuilder.withLongOpt("key").withDescription("Key to scan with.  This should be an exact key (not a regular expression").hasArg().create('k'));
    options.addOption(OptionBuilder.withLongOpt("list-tables").withDescription("List tables in HBase metastore").create('l'));
    options.addOption(OptionBuilder.withLongOpt("regex-key").withDescription("Regular expression to scan keys with.").hasArg().create('r'));
    options.addOption(OptionBuilder.withLongOpt("table").withDescription("HBase metastore table to scan").hasArg().create('t'));
    CommandLine cli = null;
    try {
        cli = new GnuParser().parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parse Exception: " + e.getMessage());
        usage(options);
        return;
    }
    if (cli.hasOption('h')) {
        usage(options);
        return;
    }
    Configuration conf = new Configuration();
    if (cli.hasOption('i')) {
        new HBaseSchemaTool().install(conf, System.err);
        return;
    }
    String key = null;
    if (cli.hasOption('k'))
        key = cli.getOptionValue('k');
    String regex = null;
    if (cli.hasOption('r'))
        regex = cli.getOptionValue('r');
    if (key != null && regex != null) {
        usage(options);
        return;
    }
    if (key == null && regex == null)
        regex = ".*";
    // I do this in the object rather than in the static main so that it's easier to test.
    new HBaseSchemaTool().go(cli.hasOption('l'), cli.getOptionValue('t'), key, regex, conf, System.out, System.err);
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Configuration(org.apache.hadoop.conf.Configuration) GnuParser(org.apache.commons.cli.GnuParser) ParseException(org.apache.commons.cli.ParseException)

Example 2 with ParseException

use of org.apache.commons.cli.ParseException 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)

Example 3 with ParseException

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

the class DbUnitDataImportExport 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(FILE_OPTION_NAME)) {
            fileName = line.getOptionValue(FILE_OPTION_NAME);
        }
        if (line.hasOption(USER_OPTION_NAME)) {
            user = line.getOptionValue(USER_OPTION_NAME);
        } else {
            missingOption(userOption);
        }
        if (line.hasOption(PASSWORD_OPTION_NAME)) {
            password = line.getOptionValue(PASSWORD_OPTION_NAME);
        } else {
            missingOption(passwordOption);
        }
        if (line.hasOption(DATABASE_OPTION_NAME)) {
            databaseName = line.getOptionValue(DATABASE_OPTION_NAME);
        }
        if (line.hasOption(IMPORT_OPTION_NAME)) {
            doExport = false;
        } else if (line.hasOption(EXPORT_OPTION_NAME)) {
            doExport = true;
            if (line.hasOption(SQL_OPTION_NAME)) {
                exportAsSql = true;
            }
        }
    } 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)

Example 4 with ParseException

use of org.apache.commons.cli.ParseException 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 5 with ParseException

use of org.apache.commons.cli.ParseException in project hadoop by apache.

the class TimelineSchemaCreator method parseArgs.

/**
   * Parse command-line arguments.
   *
   * @param args
   *          command line arguments passed to program.
   * @return parsed command line.
   * @throws ParseException
   */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();
    // Input
    Option o = new Option(ENTITY_TABLE_NAME_SHORT, "entityTableName", true, "entity table name");
    o.setArgName("entityTableName");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(TTL_OPTION_SHORT, "metricsTTL", true, "TTL for metrics column family");
    o.setArgName("metricsTTL");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(APP_TO_FLOW_TABLE_NAME_SHORT, "appToflowTableName", true, "app to flow table name");
    o.setArgName("appToflowTableName");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(APP_TABLE_NAME_SHORT, "applicationTableName", true, "application table name");
    o.setArgName("applicationTableName");
    o.setRequired(false);
    options.addOption(o);
    // Options without an argument
    // No need to set arg name since we do not need an argument here
    o = new Option(SKIP_EXISTING_TABLE_OPTION_SHORT, "skipExistingTable", false, "skip existing Hbase tables and continue to create new tables");
    o.setRequired(false);
    options.addOption(o);
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        LOG.error("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }
    return commandLine;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

ParseException (org.apache.commons.cli.ParseException)586 CommandLine (org.apache.commons.cli.CommandLine)488 CommandLineParser (org.apache.commons.cli.CommandLineParser)380 Options (org.apache.commons.cli.Options)370 DefaultParser (org.apache.commons.cli.DefaultParser)220 HelpFormatter (org.apache.commons.cli.HelpFormatter)204 GnuParser (org.apache.commons.cli.GnuParser)173 IOException (java.io.IOException)124 Option (org.apache.commons.cli.Option)109 File (java.io.File)90 PosixParser (org.apache.commons.cli.PosixParser)65 Path (org.apache.hadoop.fs.Path)50 ArrayList (java.util.ArrayList)42 Properties (java.util.Properties)35 BasicParser (org.apache.commons.cli.BasicParser)31 FileInputStream (java.io.FileInputStream)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)26 List (java.util.List)25 URI (java.net.URI)21