Java Code Examples for org.apache.commons.cli.Option#getValues()

The following examples show how to use org.apache.commons.cli.Option#getValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskAdmin.java    From helix with Apache License 2.0 6 votes vote down vote up
/** Ensures options argument counts are correct */
private static boolean checkOptionArgsNumber(Option[] options) {
  for (Option option : options) {
    int argNb = option.getArgs();
    String[] args = option.getValues();
    if (argNb == 0) {
      if (args != null && args.length > 0) {
        System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
            + Arrays.toString(args) + ")");
        return false;
      }
    } else {
      if (args == null || args.length != argNb) {
        System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
            + Arrays.toString(args) + ")");
        return false;
      }
    }
  }
  return true;
}
 
Example 2
Source File: JmxDumper.java    From helix with Apache License 2.0 6 votes vote down vote up
private static boolean checkOptionArgsNumber(Option[] options) {
  for (Option option : options) {
    int argNb = option.getArgs();
    String[] args = option.getValues();
    if (argNb == 0) {
      if (args != null && args.length > 0) {
        System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
            + Arrays.toString(args) + ")");
        return false;
      }
    } else {
      if (args == null || args.length != argNb) {
        System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
            + Arrays.toString(args) + ")");
        return false;
      }
    }
  }
  return true;
}
 
Example 3
Source File: SqoopParser.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
@Override
/**
 * Processes arguments to options but only strips matched quotes.
 */
public void processArgs(Option opt, ListIterator iter)
    throws ParseException {
  // Loop until an option is found.
  while (iter.hasNext()) {
    String str = (String) iter.next();

    if (getOptions().hasOption(str) && str.startsWith("-")) {
      // found an Option, not an argument.
      iter.previous();
      break;
    }

    // Otherwise, this is a value.
    try {
      // Note that we only strip matched quotes here.
      addValForProcessing.invoke(opt, stripMatchedQuotes(str));
    } catch (IllegalAccessException iae) {
      throw new RuntimeException(iae);
    } catch (java.lang.reflect.InvocationTargetException ite) {
      // Any runtime exception thrown within addValForProcessing()
      // will be wrapped in an InvocationTargetException.
      iter.previous();
      break;
    } catch (RuntimeException re) {
      iter.previous();
      break;
    }
  }

  if (opt.getValues() == null && !opt.hasOptionalArg()) {
    throw new MissingArgumentException(opt);
  }
}
 
Example 4
Source File: CreateTableCommand.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private Map<String, String> getProps(CommandLine cmd, String opt) {
  Map<String, String> props = new HashMap<String, String>();
  Option[] options = cmd.getOptions();
  for (Option option : options) {
    if (option.getOpt().equals(opt)) {
      String[] values = option.getValues();
      props.put(values[0], values[1]);
    }
  }
  return props;
}
 
Example 5
Source File: AddColumnDefinitionCommand.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException,
    BlurException {
  if (args.length < 5) {
    throw new CommandException("Invalid args: " + help());
  }
  CommandLine cmd = parse(args, out);

  ColumnDefinition columnDefinition = new ColumnDefinition();
  columnDefinition.setFamily(args[2]);
  columnDefinition.setColumnName(args[3]);
  columnDefinition.setFieldType(args[4]);
  if (cmd.hasOption("s")) {
    columnDefinition.setSubColumnName(cmd.getOptionValue("s"));
  }
  if (cmd.hasOption("F")) {
    columnDefinition.setFieldLessIndexed(true);
  }
  if (cmd.hasOption("S")) {
    columnDefinition.setSortable(true);
  }
  if (cmd.hasOption("p")) {
    Option[] options = cmd.getOptions();
    for (Option option : options) {
      if (option.getOpt().equals("p")) {
        String[] values = option.getValues();
        columnDefinition.putToProperties(values[0], values[1]);
      }
    }
  }
  if (cmd.hasOption('M')) {
    columnDefinition.setMultiValueField(true);
  } else {
    columnDefinition.setMultiValueField(false);
  }

  if (!client.addColumnDefinition(args[1], columnDefinition)) {
    out.println("Column Definition was not added, check to see if the column has already been added to the table.");
  }
}