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

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

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

Option.getDescription介绍

[英]Retrieve the self-documenting description of this Option
[中]检索此选项的自我记录说明

代码示例

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

if (option.getDescription() != null)
  buff.append(option.getDescription());

代码示例来源: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.getDescription() != null)
  optBuf.append(option.getDescription());

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

@Test
public void testDuplicateSimple()
{
  Options opts = new Options();
  opts.addOption("a", false, "toggle -a");
  opts.addOption("a", true, "toggle -a*");
  assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription());
}

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

@Test
public void testDuplicateLong()
{
  Options opts = new Options();
  opts.addOption("a", "--a", false, "toggle -a");
  opts.addOption("a", "--a", false, "toggle -a*");
  assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription());
}

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

if (option.getDescription() != null) {
  lineBuilder.append(option.getDescription());

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

@Test
  public void testBuilderIsResettedAlways() {
    try
    {
      OptionBuilder.withDescription("JUnit").create('"');
      fail("IllegalArgumentException expected");
    }
    catch (IllegalArgumentException e)
    {
      // expected
    }
    assertNull("we inherited a description", OptionBuilder.create('x').getDescription());

    try
    {
      OptionBuilder.withDescription("JUnit").create();
      fail("IllegalArgumentException expected");
    }
    catch (IllegalArgumentException e)
    {
      // expected
    }
    assertNull("we inherited a description", OptionBuilder.create('x').getDescription());
  }
}

代码示例来源: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

@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

@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

private static void checkOption(Option option, String opt, String description, String longOpt, int numArgs,
                String argName,  boolean required, boolean optionalArg,
                char valueSeparator, Class<?> cls)
{
  assertEquals(opt, option.getOpt());
  assertEquals(description, option.getDescription());
  assertEquals(longOpt, option.getLongOpt());
  assertEquals(numArgs, option.getArgs());
  assertEquals(argName, option.getArgName());
  assertEquals(required, option.isRequired());
  assertEquals(optionalArg, option.hasOptionalArg());
  assertEquals(valueSeparator, option.getValueSeparator());
  assertEquals(cls,  option.getType());
}

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-essentials

public void setOptionDescription(Option optionDescription) {
  this.optionDescription = optionDescription;
  // synchronize the descriptions if any is null.
  String optionDescriptionString = optionDescription.getDescription();
  if (description == null)
    description = optionDescriptionString;
  if (optionDescriptionString == null)
    optionDescription.setDescription(description);
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

private static void printProgramUsage()
{
  System.out.printf("Usage: %s -s -K <keyspace> -c <column_family> -n <num_keys> <json> <sstable>%n%n",
            SSTableImport.class.getName());
  System.out.println("Options:");
  for (Object o :  options.getOptions())
  {
    Option opt = (Option) o;
    System.out.println("  -" +opt.getOpt() + " - " + opt.getDescription());
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

public static void printHelp(String synopsis, String header)
  {
    System.out.printf("Usage: %s%n%n", synopsis);
    System.out.print(header);
    System.out.println("Options:");
    for (Object opt : options.getOptions())
    {
      String shortOpt = String.format("%s,", ((Option)opt).getOpt());
      String longOpt = ((Option)opt).getLongOpt();
      String description = ((Option)opt).getDescription();
      System.out.printf(" -%-4s --%-17s %s%n", shortOpt, longOpt, description);
    }
  }
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static void printHelp(String synopsis, String header)
  {
    System.out.printf("Usage: %s%n%n", synopsis);
    System.out.print(header);
    System.out.println("Options:");
    for (Object opt : options.getOptions())
    {
      String shortOpt = String.format("%s,", ((Option)opt).getOpt());
      String longOpt = ((Option)opt).getLongOpt();
      String description = ((Option)opt).getDescription();
      System.out.printf(" -%-4s --%-17s %s%n", shortOpt, longOpt, description);
    }
  }
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

public static void printHelp(String synopsis, String header)
  {
    System.out.printf("Usage: %s%n%n", synopsis);
    System.out.print(header);
    System.out.println("Options:");
    for (Object opt : options.getOptions())
    {
      String shortOpt = String.format("%s,", ((Option)opt).getOpt());
      String longOpt = ((Option)opt).getLongOpt();
      String description = ((Option)opt).getDescription();
      System.out.printf(" -%-4s --%-17s %s%n", shortOpt, longOpt, description);
    }
  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

public static void printHelp(String synopsis, String header)
  {
    System.out.printf("Usage: %s%n%n", synopsis);
    System.out.print(header);
    System.out.println("Options:");
    for (Object opt : options.getOptions())
    {
      String shortOpt = String.format("%s,", ((Option)opt).getOpt());
      String longOpt = ((Option)opt).getLongOpt();
      String description = ((Option)opt).getDescription();
      System.out.printf(" -%-4s --%-17s %s%n", shortOpt, longOpt, description);
    }
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-client

public boolean getHelp(String cmd, StringBuilder strcnd, boolean addDesc) {
 Option opt = options.getOption(cmd);
 if (opt != null) {
  strcnd.append(DEFAULT_SEPARATOR).append(" -").append(opt.getOpt());
  if (opt.hasArg()) {
   strcnd.append(" <").append(opt.getArgName()).append(">");
  }
  if (addDesc) {
   strcnd.append(DEFAULT_SEPARATOR).append("\t")
     .append(opt.getDescription());
  }
 }
 return opt == null;
}

代码示例来源:origin: com.marklogic/mlcp

public CommandlineOption(Option opt)
    throws IllegalArgumentException {
  super(opt.getOpt(), opt.hasArg(), opt.getDescription());
  this.setLongOpt(opt.getLongOpt());
  this.setRequired(opt.isRequired());
  this.setArgName(opt.getArgName());
  this.setArgs(opt.getArgs());
  this.setOptionalArg(opt.hasOptionalArg());
  this.setType(opt.getType());
  this.setValueSeparator(opt.getValueSeparator());
}

相关文章