org.apache.commons.cli.Option.hasArg()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(334)

本文整理了Java中org.apache.commons.cli.Option.hasArg()方法的一些代码示例,展示了Option.hasArg()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.hasArg()方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:hasArg

Option.hasArg介绍

[英]hasArg specifies whether this option has an associated argument
[中]hasArg指定此选项是否有关联的参数

代码示例

代码示例来源:origin: commons-cli/commons-cli

/**
 * Tells if the option can accept more arguments.
 * 
 * @return false if the maximum number of arguments is reached
 * @since 1.3
 */
boolean acceptsArg()
{
  return (hasArg() || hasArgs() || hasOptionalArg()) && (numberOfArgs <= 0 || values.size() < numberOfArgs);
}

代码示例来源:origin: commons-cli/commons-cli

/**
 * Add the special token "<b>--</b>" and the current <code>value</code>
 * to the processed tokens list. Then add all the remaining
 * <code>argument</code> values to the processed tokens list.
 *
 * @param value The current token
 */
private void processNonOptionToken(String value, boolean stopAtNonOption)
{
  if (stopAtNonOption && (currentOption == null || !currentOption.hasArg()))
  {
    eatTheRest = true;
    tokens.add("--");
  }
  tokens.add(value);
}

代码示例来源:origin: apache/kylin

public String getOptionsAsString() {
  StringBuilder buf = new StringBuilder();
  for (Option option : commandLine.getOptions()) {
    buf.append(" ");
    buf.append(option.getOpt());
    if (option.hasArg()) {
      buf.append("=");
      buf.append(option.getValue());
    }
  }
  return buf.toString();
}

代码示例来源:origin: commons-cli/commons-cli

else if (hasArg())

代码示例来源:origin: apache/incubator-gobblin

/**
 * For each method for which the helper created an {@link Option} and for which the input {@link CommandLine} contains
 * that option, this method will automatically call the method on the input object with the correct
 * arguments.
 */
public void applyCommandLineOptions(CommandLine cli, T embeddedGobblin) {
 try {
  for (Option option : cli.getOptions()) {
   if (!this.methodsMap.containsKey(option.getOpt())) {
    // Option added by cli driver itself.
    continue;
   }
   if (option.hasArg()) {
    this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin, option.getValue());
   } else {
    this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin);
   }
  }
 } catch (IllegalAccessException | InvocationTargetException exc) {
  throw new RuntimeException("Could not apply options to " + embeddedGobblin.getClass().getName(), exc);
 }
}

代码示例来源:origin: apache/flink

final String argument = "--" + o.getLongOpt();
if (!o.hasArg()) {
  final Boolean flag = Boolean.parseBoolean(v);

代码示例来源:origin: commons-cli/commons-cli

if (option.hasArg() && (option.getArgName() == null || option.getArgName().length() != 0))

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testCompleteOption( ) {
  Option simple = OptionBuilder.withLongOpt( "simple option")
                 .hasArg( )
                 .isRequired( )
                 .hasArgs( )
                 .withType( Float.class )
                 .withDescription( "this is a simple option" )
                 .create( 's' );
  assertEquals( "s", simple.getOpt() );
  assertEquals( "simple option", simple.getLongOpt() );
  assertEquals( "this is a simple option", simple.getDescription() );
  assertEquals( simple.getType(), Float.class );
  assertTrue( simple.hasArg() );
  assertTrue( simple.isRequired() );
  assertTrue( simple.hasArgs() );
}

代码示例来源:origin: commons-cli/commons-cli

currentOption = options.getOption(ch);
if (currentOption.hasArg() && token.length() != i + 1)

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testTwoCompleteOptions( ) {
  Option simple = OptionBuilder.withLongOpt( "simple option")
                 .hasArg( )
                 .isRequired( )
                 .hasArgs( )
                 .withType( Float.class )
                 .withDescription( "this is a simple option" )
                 .create( 's' );
  assertEquals( "s", simple.getOpt() );
  assertEquals( "simple option", simple.getLongOpt() );
  assertEquals( "this is a simple option", simple.getDescription() );
  assertEquals( simple.getType(), Float.class );
  assertTrue( simple.hasArg() );
  assertTrue( simple.isRequired() );
  assertTrue( simple.hasArgs() );
  simple = OptionBuilder.withLongOpt( "dimple option")
             .hasArg( )
             .withDescription( "this is a dimple option" )
             .create( 'd' );
  assertEquals( "d", simple.getOpt() );
  assertEquals( "dimple option", simple.getLongOpt() );
  assertEquals( "this is a dimple option", simple.getDescription() );
  assertEquals( String.class, simple.getType() );
  assertTrue( simple.hasArg() );
  assertTrue( !simple.isRequired() );
  assertTrue( !simple.hasArgs() );
}

代码示例来源:origin: commons-cli/commons-cli

if (opt.hasArg())

代码示例来源:origin: soabase/exhibitor

private void logOptions(String sectionName, String prefix, Options options)
{
  if ( sectionName != null )
  {
    log.info("== " + sectionName + " ==");
  }
  //noinspection unchecked
  for ( Option option : (Iterable<? extends Option>)options.getOptions() )
  {
    if ( option.hasLongOpt() )
    {
      if ( option.hasArg() )
      {
        log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription());
      }
      else
      {
        log.info(prefix + option.getLongOpt() + " - " + option.getDescription());
      }
    }
  }
}

代码示例来源:origin: commons-cli/commons-cli

if (option.hasArg())

代码示例来源:origin: commons-cli/commons-cli

private void handleOption(Option option) throws ParseException
{
  // check the previous option before handling the next one
  checkRequiredArgs();
  option = (Option) option.clone();
  updateRequiredOptions(option);
  cmd.addOption(option);
  if (option.hasArg())
  {
    currentOption = option;
  }
  else
  {
    currentOption = null;
  }
}

代码示例来源:origin: commons-cli/commons-cli

if (opt.hasArg())

代码示例来源:origin: embulk/embulk

if (option.hasArg()) {
  final String argName = option.getArgName();
  if (argName != null && argName.length() == 0) {

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testBaseOptionStringOpt() {
  Option base = OptionBuilder.withDescription( "option description")
                .create( "o" );
  assertEquals( "o", base.getOpt() );
  assertEquals( "option description", base.getDescription() );
  assertTrue( !base.hasArg() );
}

代码示例来源:origin: commons-cli/commons-cli

@Test
public void testBaseOptionCharOpt() {
  Option base = OptionBuilder.withDescription( "option description")
                .create( 'o' );
  assertEquals( "o", base.getOpt() );
  assertEquals( "option description", base.getDescription() );
  assertTrue( !base.hasArg() );
}

代码示例来源:origin: commons-cli/commons-cli

if (opt.hasArg())

代码示例来源:origin: apache/metron

public Map.Entry<AMOptions, String> of(String value) {
 if(option.hasArg()) {
  return new AbstractMap.SimpleEntry<>(this, value);
 }
 return new AbstractMap.SimpleEntry<>(this, null);
}

相关文章