Example usage for org.apache.commons.cli Option getOpt

List of usage examples for org.apache.commons.cli Option getOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getOpt.

Prototype

public String getOpt() 

Source Link

Document

Retrieve the name of this Option.

Usage

From source file:no.antares.clutil.hitman.CommandLineOptions.java

protected CommandLineOptions(String[] args) {
    addOption("help", "print this message");
    Option portArg = addOption("port", "port to bind to", "port");
    Option signalArg = addOption("cmd", "command (process) to run", "command");
    Option messageArg = addOption("sig", "signal to send", "signal");

    CommandLineParser parser = new GnuParser();
    CommandLine cmd;/* www .  j a v a  2  s. co m*/
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        throw new RuntimeException("Error parsing", pe);
    }

    String port = cmd.getOptionValue(portArg.getOpt(), null);
    if (port == null)
        portNo = null;
    else
        portNo = Integer.valueOf(port);
    signal = cmd.getOptionValue(messageArg.getOpt(), null);
    command = cmd.getOptionValue(signalArg.getOpt(), null);
}

From source file:openlr.otk.options.CommandLineData.java

/**
 * Check required options./*from  ww  w. j  av  a 2s.  c  om*/
 * 
 * @param cmdLine
 *            the cmd line
 * @throws CommandLineParseException
 *             the parse exception
 */
private void checkRequiredOptions(final CommandLine cmdLine) throws CommandLineParseException {

    for (Option opt : cmdLine.getOptions()) {
        if (opt.isRequired() && !cmdLine.hasOption(opt.getOpt())) {
            throw new CommandLineParseException("Missing mandatory parameter: " + opt.getOpt());
        }
    }
}

From source file:openlr.otk.options.InputFileOrStdInOption.java

/**
 * Instantiates a new input file option.
 *//*from w w w  . j av  a 2  s  . c  o  m*/
public InputFileOrStdInOption() {
    super("i", "input-file", true,
            "The path to the input file, if this option is missing the tool awaits input from standard input",
            false);
    Option option = getOption();
    delegatedPureFileOption = new InputFileOption(option.getOpt(), option.getLongOpt(), option.getDescription(),
            false);
}

From source file:openlr.otk.options.OutputFileOrStdOutOption.java

/**
 * Instantiates a new output file option.
 * @param failIfFileAlreadyExists//from   w w  w.  java 2 s.co m
 *            A flag that determines whether this option processor should
 *            fail during {@link #parse(String, Object...)} if the specified
 *            target file already exists.
 */
public OutputFileOrStdOutOption(final boolean failIfFileAlreadyExists) {
    super("o", "output-file", true,
            "path to the the output file [if missing output is written to standard out]", false);
    Option option = getOption();
    delegatedPureFileOption = new FileOption(option.getOpt(), option.getLongOpt(), option.getDescription(),
            false, failIfFileAlreadyExists);
}

From source file:openlr.otk.options.UsageBuilder.java

/**
 * Builds the string displaying the list of available options in one row.
 * /*from w  w w  .  jav a2s.  co m*/
 * @param options
 *            The tool options
 * @return The string listing all available options.
 */
private static String buildOptionsList(final Options options) {

    Collection<?> optionsColl = options.getOptions();
    List<String> required = new ArrayList<String>(optionsColl.size());
    List<String> optional = new ArrayList<String>(optionsColl.size());

    for (Object option : optionsColl) {
        Option opt = (Option) option;
        if (opt.isRequired()) {
            required.add(opt.getOpt());

        } else {
            optional.add(opt.getOpt());
        }
    }
    return buildFormattedLists(required, optional, "-%s");
}

From source file:org.apache.accumulo.core.file.rfile.SplitLarge.java

public static void main(String[] args) throws Exception {
    Configuration conf = CachedConfiguration.getInstance();
    FileSystem fs = FileSystem.get(conf);
    long maxSize = 10 * 1024 * 1024;

    Options opts = new Options();
    Option maxSizeOption = new Option("m", "", true,
            "the maximum size of the key/value pair to shunt to the small file");
    opts.addOption(maxSizeOption);// w  ww  .  j a v  a 2  s.co  m

    CommandLine commandLine = new BasicParser().parse(opts, args);
    if (commandLine.hasOption(maxSizeOption.getOpt())) {
        maxSize = Long.parseLong(commandLine.getOptionValue(maxSizeOption.getOpt()));
    }

    for (String arg : commandLine.getArgs()) {
        Path path = new Path(arg);
        CachableBlockFile.Reader rdr = new CachableBlockFile.Reader(fs, path, conf, null, null);
        Reader iter = new RFile.Reader(rdr);

        if (!arg.endsWith(".rf")) {
            throw new IllegalArgumentException("File must end with .rf");
        }
        String smallName = arg.substring(0, arg.length() - 3) + "_small.rf";
        String largeName = arg.substring(0, arg.length() - 3) + "_large.rf";

        int blockSize = (int) DefaultConfiguration.getDefaultConfiguration()
                .getMemoryInBytes(Property.TABLE_FILE_BLOCK_SIZE);
        Writer small = new RFile.Writer(new CachableBlockFile.Writer(fs, new Path(smallName), "gz", conf),
                blockSize);
        small.startDefaultLocalityGroup();
        Writer large = new RFile.Writer(new CachableBlockFile.Writer(fs, new Path(largeName), "gz", conf),
                blockSize);
        large.startDefaultLocalityGroup();

        iter.seek(new Range(), new ArrayList<ByteSequence>(), false);
        while (iter.hasTop()) {
            Key key = iter.getTopKey();
            Value value = iter.getTopValue();
            if (key.getSize() + value.getSize() < maxSize) {
                small.append(key, value);
            } else {
                large.append(key, value);
            }
            iter.next();
        }

        iter.close();
        large.close();
        small.close();
    }
}

From source file:org.apache.accumulo.core.util.shell.commands.SetScanIterCommand.java

@Override
public Options getOptions() {
    // Remove the options that specify which type of iterator this is, since
    // they are all scan iterators with this command.
    final HashSet<OptionGroup> groups = new HashSet<OptionGroup>();
    final Options parentOptions = super.getOptions();
    final Options modifiedOptions = new Options();
    for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) {
        Option o = (Option) it.next();
        if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt())
                && !IteratorScope.scan.name().equals(o.getOpt())) {
            modifiedOptions.addOption(o);
            OptionGroup group = parentOptions.getOptionGroup(o);
            if (group != null)
                groups.add(group);/*from  w  ww.j  ava2  s  .  com*/
        }
    }
    for (OptionGroup group : groups) {
        modifiedOptions.addOptionGroup(group);
    }
    return modifiedOptions;
}

From source file:org.apache.accumulo.core.util.shell.commands.SetShellIterCommand.java

@Override
public Options getOptions() {
    // Remove the options that specify which type of iterator this is, since
    // they are all scan iterators with this command.
    final HashSet<OptionGroup> groups = new HashSet<OptionGroup>();
    final Options parentOptions = super.getOptions();
    final Options modifiedOptions = new Options();
    for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) {
        Option o = (Option) it.next();
        if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt())
                && !IteratorScope.scan.name().equals(o.getOpt()) && !"table".equals(o.getLongOpt())) {
            modifiedOptions.addOption(o);
            OptionGroup group = parentOptions.getOptionGroup(o);
            if (group != null)
                groups.add(group);/*from  w w w  .j av  a 2s. c  o  m*/
        }
    }
    for (OptionGroup group : groups) {
        modifiedOptions.addOptionGroup(group);
    }

    profileOpt = new Option("pn", "profile", true, "iterator profile name");
    profileOpt.setRequired(true);
    profileOpt.setArgName("profile");

    modifiedOptions.addOption(profileOpt);

    return modifiedOptions;
}

From source file:org.apache.accumulo.examples.simple.client.ReadWriteExample.java

private boolean hasOpt(Option opt) {
    return cl.hasOption(opt.getOpt());
}

From source file:org.apache.accumulo.examples.simple.client.ReadWriteExample.java

private String getOpt(Option opt, String defaultValue) {
    return cl.getOptionValue(opt.getOpt(), defaultValue);
}