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

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

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:org.apache.hadoop.hive.metastore.hbase.HBaseSchemaTool.java

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;//from  w  ww. j ava  2s . co m
    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);
}

From source file:org.apache.hadoop.hive.ql.io.orc.FileDump.java

static Options createOptions() {
    Options result = new Options();

    // add -d and --data to print the rows
    result.addOption(/* w w w  . j  a  v a 2 s .c om*/
            OptionBuilder.withLongOpt("data").withDescription("Should the data be printed").create('d'));

    // to avoid breaking unit tests (when run in different time zones) for file dump, printing
    // of timezone is made optional
    result.addOption(
            OptionBuilder.withLongOpt("timezone").withDescription("Print writer's time zone").create('t'));

    result.addOption(OptionBuilder.withLongOpt("help").withDescription("print help message").create('h'));

    result.addOption(OptionBuilder.withLongOpt("rowindex")
            .withArgName("comma separated list of column ids for which row index should be printed")
            .withDescription("Dump stats for column number(s)").hasArg().create('r'));

    result.addOption(
            OptionBuilder.withLongOpt("json").withDescription("Print metadata in JSON format").create('j'));

    result.addOption(OptionBuilder.withLongOpt("pretty").withDescription("Pretty print json metadata output")
            .create('p'));

    return result;
}

From source file:org.apache.hadoop.hive.ql.io.orc.FixAcidKeyIndex.java

static Options createOptions() {
    Options result = new Options();

    result.addOption(OptionBuilder.withLongOpt("check-only")
            .withDescription("Check acid orc file for valid acid key index and exit without fixing")
            .create('c'));

    result.addOption(OptionBuilder.withLongOpt("recover")
            .withDescription("Fix the acid key index for acid orc file if it requires fixing").create('r'));

    result.addOption(OptionBuilder.withLongOpt("backup-path")
            .withDescription("specify a backup path to store the corrupted files (default: /tmp)").hasArg()
            .create());//from  ww  w. j av a2s. co  m

    result.addOption(OptionBuilder.withLongOpt("help").withDescription("print help message").create('h'));

    return result;
}

From source file:org.apache.hadoop.hive.ql.session.ClearDanglingScratchDir.java

static Options createOptions() {
    Options result = new Options();

    // add -r and --dry-run to generate list only
    result.addOption(OptionBuilder.withLongOpt("dry-run")
            .withDescription("Generate a list of dangling scratch dir, printed on console").create('r'));

    // add -s and --scratchdir to specify a non-default scratch dir
    result.addOption(OptionBuilder.withLongOpt("scratchdir")
            .withDescription("Specify a non-default location of the scratch dir").hasArg().create('s'));

    // add -v and --verbose to print verbose message
    result.addOption(OptionBuilder.withLongOpt("verbose").withDescription("Print verbose message").create('v'));

    result.addOption(OptionBuilder.withLongOpt("help").withDescription("print help message").create('h'));

    return result;
}

From source file:org.apache.hadoop.hive.ql.util.HiveStrictManagedMigration.java

static Options createOptions() {
    Options result = new Options();

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

    result.addOption(OptionBuilder.withLongOpt("dryRun")
            .withDescription("Show what migration actions would be taken without actually running commands")
            .create());//from w ww .  java2 s  .c  o m

    result.addOption(OptionBuilder.withLongOpt("dbRegex")
            .withDescription("Regular expression to match database names on which this tool will be run")
            .hasArg().create('d'));

    result.addOption(OptionBuilder.withLongOpt("tableRegex")
            .withDescription("Regular expression to match table names on which this tool will be run").hasArg()
            .create('t'));

    result.addOption(OptionBuilder.withLongOpt("oldWarehouseRoot")
            .withDescription("Location of the previous warehouse root").hasArg().create());

    result.addOption(OptionBuilder.withLongOpt("migrationOption")
            .withDescription("Table migration option (automatic|external|managed|validate|none)").hasArg()
            .create('m'));

    result.addOption(OptionBuilder.withLongOpt("shouldModifyManagedTableLocation").withDescription(
            "Whether managed tables should have their data moved from the old warehouse path to the current warehouse path")
            .create());

    result.addOption(OptionBuilder.withLongOpt("shouldModifyManagedTableOwner")
            .withDescription(
                    "Whether managed tables should have their directory owners changed to the hive user")
            .create());

    result.addOption(OptionBuilder.withLongOpt("shouldModifyManagedTablePermissions").withDescription(
            "Whether managed tables should have their directory permissions changed to conform to strict managed tables mode")
            .create());

    result.addOption(OptionBuilder.withLongOpt("modifyManagedTables").withDescription(
            "This setting enables the shouldModifyManagedTableLocation, shouldModifyManagedTableOwner, shouldModifyManagedTablePermissions options")
            .create());

    result.addOption(OptionBuilder.withLongOpt("help").withDescription("print help message").create('h'));

    return result;
}

From source file:org.apache.hadoop.util.ConfTest.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
    GenericOptionsParser genericParser = new GenericOptionsParser(args);
    String[] remainingArgs = genericParser.getRemainingArgs();

    Option conf = OptionBuilder.hasArg().create("conffile");
    Option help = OptionBuilder.withLongOpt("help").create('h');
    Options opts = new Options().addOption(conf).addOption(help);
    CommandLineParser specificParser = new GnuParser();
    CommandLine cmd = null;//ww w.j  a  va2 s  . c o  m
    try {
        cmd = specificParser.parse(opts, remainingArgs);
    } catch (MissingArgumentException e) {
        terminate(1, "No argument specified for -conffile option");
    } catch (ParseException e) {
        terminate(1, USAGE);
    }
    if (cmd == null) {
        terminate(1, "Failed to parse options");
    }

    if (cmd.hasOption('h')) {
        terminate(0, USAGE);
    }

    List<File> files = new ArrayList<File>();
    if (cmd.hasOption("conffile")) {
        String[] values = cmd.getOptionValues("conffile");
        for (String value : values) {
            File confFile = new File(value);
            if (confFile.isFile()) {
                files.add(confFile);
            } else if (confFile.isDirectory()) {
                for (File file : listFiles(confFile)) {
                    files.add(file);
                }
            } else {
                terminate(1, confFile.getAbsolutePath() + " is neither a file nor directory");
            }
        }
    } else {
        String confDirName = System.getenv(HADOOP_CONF_DIR);
        if (confDirName == null) {
            terminate(1, HADOOP_CONF_DIR + " does not defined");
        }
        File confDir = new File(confDirName);
        if (!confDir.isDirectory()) {
            terminate(1, HADOOP_CONF_DIR + " is not a directory");
        }
        files = Arrays.asList(listFiles(confDir));
    }
    if (files.isEmpty()) {
        terminate(1, "No input file to validate");
    }

    boolean ok = true;
    for (File file : files) {
        String path = file.getAbsolutePath();
        List<String> errors = checkConf(new FileInputStream(file));
        if (errors.isEmpty()) {
            System.out.println(path + ": valid");
        } else {
            ok = false;
            System.err.println(path + ":");
            for (String error : errors) {
                System.err.println("\t" + error);
            }
        }
    }
    if (ok) {
        System.out.println("OK");
    } else {
        terminate(1, "Invalid file exists");
    }
}

From source file:org.apache.helix.agent.HelixAgentMain.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();//  w  ww .j  a va2 s . co m

    Option zkAddrOption = OptionBuilder.withLongOpt(zkAddr).hasArgs(1).isRequired(true)
            .withArgName("ZookeeperServerAddress(Required)").withDescription("Provide zookeeper address")
            .create();

    Option clusterOption = OptionBuilder.withLongOpt(cluster).hasArgs(1).isRequired(true)
            .withArgName("Cluster name (Required)").withDescription("Provide cluster name").create();

    Option instanceNameOption = OptionBuilder.withLongOpt(instanceName).hasArgs(1).isRequired(true)
            .withArgName("Helix agent name (Required)").withDescription("Provide Helix agent name").create();

    Option stateModelOption = OptionBuilder.withLongOpt(stateModel).hasArgs(1).isRequired(true)
            .withArgName("State model name (Required)").withDescription("Provide state model name").create();

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkAddrOption);
    options.addOption(clusterOption);
    options.addOption(instanceNameOption);
    options.addOption(stateModelOption);

    return options;
}

From source file:org.apache.helix.controller.HelixControllerMain.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from w  ww .java2s  .  c  o m*/

    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 modeOption = OptionBuilder.withLongOpt(mode)
            .withDescription("Provide cluster controller mode (Optional): STANDALONE (default) or DISTRIBUTED")
            .create();
    modeOption.setArgs(1);
    modeOption.setRequired(false);
    modeOption.setArgName("Cluster controller mode (Optional)");

    Option controllerNameOption = OptionBuilder.withLongOpt(name)
            .withDescription("Provide cluster controller name (Optional)").create();
    controllerNameOption.setArgs(1);
    controllerNameOption.setRequired(false);
    controllerNameOption.setArgName("Cluster controller name (Optional)");

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(modeOption);
    options.addOption(controllerNameOption);

    return options;
}

From source file:org.apache.helix.mock.participant.DummyProcess.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from w ww .j av  a 2  s  . co  m*/

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

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option cmTypeOption = OptionBuilder.withLongOpt(helixManagerType)
            .withDescription("Provide cluster manager type (e.g. 'zk', 'static-file', or 'dynamic-file'")
            .create();
    cmTypeOption.setArgs(1);
    cmTypeOption.setRequired(true);
    cmTypeOption.setArgName("Clsuter manager type (e.g. 'zk', 'static-file', or 'dynamic-file') (Required)");

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required for zk-based cluster manager)");

    // Option rootNsOption = OptionBuilder.withLongOpt(rootNamespace)
    // .withDescription("Provide root namespace for dynamic-file based cluster manager").create();
    // rootNsOption.setArgs(1);
    // rootNsOption.setRequired(true);
    // rootNsOption.setArgName("Root namespace (Required for dynamic-file based cluster manager)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(transDelayOption);
    options.addOption(cmTypeOption);

    options.addOptionGroup(optionGroup);

    return options;
}

From source file:org.apache.helix.provisioning.tools.ContainerAdmin.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Option zkServerOption = OptionBuilder.withLongOpt("zookeeperAddress")
            .withDescription("Provide zookeeper address").create();
    zkServerOption.setArgs(1);//from   ww  w . j a v  a 2 s. c  o  m
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("zookeeperAddress(Required)");

    OptionGroup group = new OptionGroup();
    group.setRequired(true);

    // update container count per service
    Option stopContainerOption = OptionBuilder.withLongOpt(stopContainer)
            .withDescription("appName participantName").create();
    stopContainerOption.setArgs(2);
    stopContainerOption.setRequired(false);
    stopContainerOption.setArgName("appName participantName");

    group.addOption(stopContainerOption);

    Options options = new Options();
    options.addOption(zkServerOption);
    options.addOptionGroup(group);
    CommandLine cliParser = new GnuParser().parse(options, args);

    String zkAddress = cliParser.getOptionValue("zookeeperAddress");
    ContainerAdmin admin = new ContainerAdmin(zkAddress);

    if (cliParser.hasOption(stopContainer)) {
        String appName = cliParser.getOptionValues(stopContainer)[0];
        String participantName = cliParser.getOptionValues(stopContainer)[1];
        admin.stopContainer(appName, participantName);
    }
}