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

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

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

Option.builder介绍

[英]Returns a Builder to create an Option using descriptive methods.
[中]返回使用描述性方法创建选项的生成器。

代码示例

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

/**
 * Returns a {@link Builder} to create an {@link Option} using descriptive
 * methods.  
 * 
 * @return a new {@link Builder} instance
 * @since 1.3
 */
public static Builder builder()
{
  return builder(null);
}

代码示例来源:origin: sleekbyte/tailor

/**
 * Create command line option with short name, long name, and no argument.
 *
 * @param shortOpt short version of option
 * @param longOpt  long version of option
 * @param desc     description of option
 */
private Option createNoArgOpt(String shortOpt, String longOpt, String desc) {
  return Option.builder(shortOpt).longOpt(longOpt).desc(desc).build();
}

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

private static Options createHelpOptions() {
 final Options options = new Options();
 options.addOption(Option.builder(HELP_KEY).longOpt("help")
   .desc("print this message").build());
 return options;
}

代码示例来源:origin: sleekbyte/tailor

/**
 * Create command line option with only long name and no argument.
 *
 * @param longOpt long version of option
 * @param desc    description of option
 */
private Option createNoArgOpt(String longOpt, String desc) {
  return Option.builder().longOpt(longOpt).desc(desc).build();
}

代码示例来源:origin: Alluxio/alluxio

@Override
public Options getOptions() {
 return new Options().addOption(Option.builder(REPLICATION)
   .required(false)
   .hasArg(true)
   .desc("number of replicas to have for each block of the loaded file")
   .build());
}

代码示例来源:origin: Alluxio/alluxio

@Override
public Options getOptions() {
 return new Options().addOption(
   Option.builder("f")
     .required(false)
     .hasArg()
     .desc("format")
     .build()
 );
}

代码示例来源:origin: sleekbyte/tailor

/**
 * Create command line option with short name, long name, and only one argument.
 *
 * @param shortOpt short version of option
 * @param longOpt  long version of option
 * @param argName  name of argument for help message
 * @param desc     description of option
 */
private Option createSingleArgOpt(String shortOpt, String longOpt, String argName, String desc) {
  return Option.builder(shortOpt).longOpt(longOpt).hasArg().argName(argName).desc(desc).build();
}

代码示例来源:origin: sleekbyte/tailor

/**
 * Create command line option with only long name and only one argument.
 *
 * @param longOpt long version of option
 * @param argName name of argument for help message
 * @param desc    description of option
 */
private Option createSingleArgOpt(String longOpt, String argName, String desc) {
  return Option.builder().longOpt(longOpt).hasArg().argName(argName).desc(desc).build();
}

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

private static Options initOptions(Options options) {
 options.addOption(new Option(StringUtils.EMPTY + HELP_OPTION, "print this message"));
 options.addOption(Option.builder(StringUtils.EMPTY + PLAIN_PWD_OPTION).argName("plain password").hasArg()
   .desc("plain password to be encrypted").build());
 options.addOption(Option.builder(StringUtils.EMPTY + MASTER_PWD_OPTION).argName("master password").hasArg()
   .desc("master password used to encrypt the plain password").build());
 options.addOption(Option.builder(StringUtils.EMPTY + MASTER_PWD_FILE_OPTION).argName("master password file")
   .hasArg().desc("file that contains the master password used to encrypt the plain password").build());
 options.addOption(new Option(StringUtils.EMPTY + STRONG_ENCRYPTOR_OPTION, "use strong encryptor"));
 options.addOption(Option.builder(StringUtils.EMPTY + ENCRYPTED_PWD_OPTION).argName("decrypt the input").hasArg().build());
 return options;
}

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

private Options buildExpectedOptions() {
 final Options options = new Options();
 for (final Map.Entry<String, String> entry : OPTIONS_MAP.entrySet()) {
  final Option option =
    Option.builder(null).required(true).longOpt(entry.getKey()).desc(entry.getValue()).hasArg().build();
  options.addOption(option);
 }
 return options;
}

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

private static Options createOptions() {
  final Options options = createHelpOptions();

  options.addOption(Option.builder(PLAINTEXT_KEY).longOpt("plaintext").hasArg().required()
    .desc("Plaintext that needs to be encrypted")
    .argName("plainText").build());

  options.addOption(Option.builder(PASSPHRASE_KEY).longOpt("key").hasArg().required()
    .desc("Passphrase used for encrypting plain text")
    .argName("pass phrase").build());

  options.addOption(Option.builder(VERSION_KEY).longOpt("version").hasArg().required()
    .desc("Version it will use to encrypt Version: " + Version.versionStrings())
    .argName("crypto version").build());

  return options;
 }
}

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

private Options getOptions() {
  Options options = new Options();
  options.addOption(Option.builder().longOpt("prefix").build());
  options.addOption(Option.builder().longOpt("prefixplusplus").build());
  return options;
}

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

@Before
public void setUp() throws Exception {
  parser = new DefaultParser();
  Option optionT1 = Option.builder("t1").hasArg().numberOfArgs(1).optionalArg(true).argName("t1_path").build();
  Option optionA = Option.builder("a").hasArg(false).build();
  Option optionB = Option.builder("b").hasArg(false).build();
  Option optionLast = Option.builder("last").hasArg(false).build();
  options = new Options().addOption(optionT1).addOption(optionA).addOption(optionB).addOption(optionLast);
}

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

@Test(expected=IllegalArgumentException.class)
public void testBuilderInsufficientParams1()
{
  Option.builder().desc("desc").build();
}

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

@Test(expected=IllegalArgumentException.class)
public void testBuilderInsufficientParams2()
{
  Option.builder(null).desc("desc").build();
}

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

@Test
  public void testUsageWithLongOptSeparator() throws Exception
  {
    Options options = new Options();
    options.addOption( "f", true, "the file" );
    options.addOption(Option.builder("s").longOpt("size").desc("the size").hasArg().argName("SIZE").build());
    options.addOption(Option.builder().longOpt("age").desc("the age").hasArg().build());
    
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLongOptSeparator("=");
    
    StringWriter out = new StringWriter();
    
    formatter.printUsage(new PrintWriter(out), 80, "create", options);
    
    assertEquals("usage: create [--age=<arg>] [-f <arg>] [-s <SIZE>]", out.toString().trim());
  }
}

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

@Test
public void testDefaultArgName()
{
  Option option = Option.builder("f").hasArg().required(true).build();
  
  Options options = new Options();
  options.addOption(option);
  
  StringWriter out = new StringWriter();
  HelpFormatter formatter = new HelpFormatter();
  formatter.setArgName("argument");
  formatter.printUsage(new PrintWriter(out), 80, "app", options);
  assertEquals("usage: app -f <argument>" + EOL, out.toString());
}

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

@Test
public void testPrintOptionGroupUsage()
{
  OptionGroup group = new OptionGroup();
  group.addOption(Option.builder("a").build());
  group.addOption(Option.builder("b").build());
  group.addOption(Option.builder("c").build());
  Options options = new Options();
  options.addOptionGroup(group);
  StringWriter out = new StringWriter();
  HelpFormatter formatter = new HelpFormatter();
  formatter.printUsage(new PrintWriter(out), 80, "app", options);
  assertEquals("usage: app [-a | -b | -c]" + EOL, out.toString());
}

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

@Test
public void testPrintRequiredOptionGroupUsage()
{
  OptionGroup group = new OptionGroup();
  group.addOption(Option.builder("a").build());
  group.addOption(Option.builder("b").build());
  group.addOption(Option.builder("c").build());
  group.setRequired(true);
  Options options = new Options();
  options.addOptionGroup(group);
  StringWriter out = new StringWriter();
  HelpFormatter formatter = new HelpFormatter();
  formatter.printUsage(new PrintWriter(out), 80, "app", options);
  assertEquals("usage: app -a | -b | -c" + EOL, out.toString());
}

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

@Test
  public void testBuilder()
    throws Exception
  {
    CommandLine.Builder builder = new CommandLine.Builder();
    builder.addArg( "foo" ).addArg( "bar" );
    builder.addOption( Option.builder( "T" ).build() );
    CommandLine cmd = builder.build();

    assertEquals( "foo", cmd.getArgs()[0] );
    assertEquals( "bar", cmd.getArgList().get( 1 ) );
    assertEquals( "T", cmd.getOptions()[0].getOpt() );
  }
}

相关文章