joptsimple.ArgumentAcceptingOptionSpec.withValuesConvertedBy()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(17.9k)|赞(0)|评价(0)|浏览(136)

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

ArgumentAcceptingOptionSpec.withValuesConvertedBy介绍

[英]Specifies a converter to use to translate arguments of this spec's option into Java objects. This is useful when converting to types that do not have the requisite factory method or constructor for #ofType(Class).

Invoking this method will trump any previous calls to this method or to #ofType(Class).
[中]指定用于将此规范选项的参数转换为Java对象的转换器。这在转换为不具有#of type(Class)所需的工厂方法或构造函数的类型时非常有用。
调用此方法将胜过以前对此方法或#of type(Class)的任何调用。

代码示例

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

.ofType(ClientUpdateCheckMode.class)
.defaultsTo(ClientUpdateCheckMode.AUTO)
.withValuesConvertedBy(new EnumConverter<ClientUpdateCheckMode>(ClientUpdateCheckMode.class)

代码示例来源:origin: org.elasticsearch/elasticsearch

Elasticsearch() {
  super("starts elasticsearch", () -> {}); // we configure logging later so we override the base class from configuring logging
  versionOption = parser.acceptsAll(Arrays.asList("V", "version"),
    "Prints elasticsearch version information and exits");
  daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
    "Starts Elasticsearch in the background")
    .availableUnless(versionOption);
  pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
    "Creates a pid file in the specified path on start")
    .availableUnless(versionOption)
    .withRequiredArg()
    .withValuesConvertedBy(new PathConverter());
  quietOption = parser.acceptsAll(Arrays.asList("q", "quiet"),
    "Turns off standard output/error streams logging in console")
    .availableUnless(versionOption)
    .availableUnless(daemonizeOption);
}

代码示例来源:origin: jopt-simple/jopt-simple

/**
 * <p>Specifies a type to which arguments of this spec's option are to be converted.</p>
 *
 * <p>JOpt Simple accepts types that have either:</p>
 *
 * <ol>
 *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
 *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
 *   primitive wrapper classes have such methods.</li>
 *
 *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
 * </ol>
 *
 * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
 * before a one-{@link String}-arg constructor would.</p>
 *
 * <p>Invoking this method will trump any previous calls to this method or to
 * {@link #withValuesConvertedBy(ValueConverter)}.</p>
 *
 * @param <T> represents the runtime class of the desired option argument type
 * @param argumentType desired type of arguments to this spec's option
 * @return self, so that the caller can add clauses to the fluent interface sentence
 * @throws NullPointerException if the type is {@code null}
 * @throws IllegalArgumentException if the type does not have the standard conversion methods
 */
public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) {
  return withValuesConvertedBy( findConverter( argumentType ) );
}

代码示例来源:origin: io.snappydata/gemfire-util

/**
 * <p>Specifies a type to which arguments of this spec's option are to be converted.</p>
 *
 * <p>JOpt Simple accepts types that have either:</p>
 *
 * <ol>
 *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
 *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
 *   primitive wrapper classes have such methods.</li>
 *
 *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
 * </ol>
 *
 * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
 * before a one-{@link String}-arg constructor would.</p>
 *
 * <p>Invoking this method will trump any previous calls to this method or to
 * {@link #withValuesConvertedBy(ValueConverter)}.
 *
 * @param <T> represents the runtime class of the desired option argument type
 * @param argumentType desired type of arguments to this spec's option
 * @return self, so that the caller can add clauses to the fluent interface sentence
 * @throws NullPointerException if the type is {@code null}
 * @throws IllegalArgumentException if the type does not have the standard conversion methods
 */
public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) {
  return withValuesConvertedBy( findConverter( argumentType ) );
}

代码示例来源:origin: net.sf.jopt-simple/jopt-simple

/**
 * <p>Specifies a type to which arguments of this spec's option are to be converted.</p>
 *
 * <p>JOpt Simple accepts types that have either:</p>
 *
 * <ol>
 *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
 *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
 *   primitive wrapper classes have such methods.</li>
 *
 *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
 * </ol>
 *
 * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
 * before a one-{@link String}-arg constructor would.</p>
 *
 * <p>Invoking this method will trump any previous calls to this method or to
 * {@link #withValuesConvertedBy(ValueConverter)}.</p>
 *
 * @param <T> represents the runtime class of the desired option argument type
 * @param argumentType desired type of arguments to this spec's option
 * @return self, so that the caller can add clauses to the fluent interface sentence
 * @throws NullPointerException if the type is {@code null}
 * @throws IllegalArgumentException if the type does not have the standard conversion methods
 */
public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) {
  return withValuesConvertedBy( findConverter( argumentType ) );
}

代码示例来源:origin: org.apache.geode/geode-joptsimple

/**
 * <p>Specifies a type to which arguments of this spec's option are to be converted.</p>
 *
 * <p>JOpt Simple accepts types that have either:</p>
 *
 * <ol>
 *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
 *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
 *   primitive wrapper classes have such methods.</li>
 *
 *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
 * </ol>
 *
 * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
 * before a one-{@link String}-arg constructor would.</p>
 *
 * <p>Invoking this method will trump any previous calls to this method or to
 * {@link #withValuesConvertedBy(ValueConverter)}.
 *
 * @param <T> represents the runtime class of the desired option argument type
 * @param argumentType desired type of arguments to this spec's option
 * @return self, so that the caller can add clauses to the fluent interface sentence
 * @throws NullPointerException if the type is {@code null}
 * @throws IllegalArgumentException if the type does not have the standard conversion methods
 */
public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) {
  return withValuesConvertedBy( findConverter( argumentType ) );
}

代码示例来源:origin: io.snappydata/gemfire-joptsimple

/**
 * <p>Specifies a type to which arguments of this spec's option are to be converted.</p>
 *
 * <p>JOpt Simple accepts types that have either:</p>
 *
 * <ol>
 *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
 *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
 *   primitive wrapper classes have such methods.</li>
 *
 *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
 * </ol>
 *
 * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
 * before a one-{@link String}-arg constructor would.</p>
 *
 * <p>Invoking this method will trump any previous calls to this method or to
 * {@link #withValuesConvertedBy(ValueConverter)}.
 *
 * @param <T> represents the runtime class of the desired option argument type
 * @param argumentType desired type of arguments to this spec's option
 * @return self, so that the caller can add clauses to the fluent interface sentence
 * @throws NullPointerException if the type is {@code null}
 * @throws IllegalArgumentException if the type does not have the standard conversion methods
 */
public final <T> ArgumentAcceptingOptionSpec<T> ofType( Class<T> argumentType ) {
  return withValuesConvertedBy( findConverter( argumentType ) );
}

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

private static ArgumentAcceptingOptionSpec<Class<? extends IExternalConverter>> makeConverterDisabledSpec(OptionParser optionParser) {
  return optionParser
      .acceptsAll(Arrays.asList(
          CommandDescription.ARGUMENT_LONG_DISABLED_CONVERTER,
          CommandDescription.ARGUMENT_SHORT_DISABLED_CONVERTER),
          CommandDescription.DESCRIPTION_CONTEXT_DISABLED_CONVERTER
      )
      .withRequiredArg()
      .describedAs(CommandDescription.DESCRIPTION_ARGUMENT_DISABLED_CONVERTER)
      .withValuesConvertedBy(new ExternalConverterValueConverter());
}

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

private static ArgumentAcceptingOptionSpec<Class<? extends IExternalConverter>> makeConverterEnabledSpec(OptionParser optionParser) {
  return optionParser
      .acceptsAll(Arrays.asList(
          CommandDescription.ARGUMENT_LONG_ENABLED_CONVERTER,
          CommandDescription.ARGUMENT_SHORT_ENABLED_CONVERTER),
          CommandDescription.DESCRIPTION_CONTEXT_ENABLED_CONVERTER
      )
      .withRequiredArg()
      .describedAs(CommandDescription.DESCRIPTION_ARGUMENT_ENABLED_CONVERTER)
      .withValuesConvertedBy(new ExternalConverterValueConverter());
}

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

private static ArgumentAcceptingOptionSpec<Level> makeLogLevelSpec(OptionParser optionParser) {
  return optionParser
      .acceptsAll(Arrays.asList(
          CommandDescription.ARGUMENT_LONG_LOG_LEVEL,
          CommandDescription.ARGUMENT_SHORT_LOG_LEVEL),
          CommandDescription.DESCRIPTION_CONTEXT_LOG_LEVEL
      )
      .withRequiredArg()
      .describedAs(CommandDescription.DESCRIPTION_ARGUMENT_LOG_LEVEL)
      .withValuesConvertedBy(new LogLevelValueConverter())
      .defaultsTo(Level.WARN);
}

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

private static ArgumentAcceptingOptionSpec<Level> makeLogLevelSpec(OptionParser optionParser) {
  return optionParser
      .acceptsAll(Arrays.asList(
          CommandDescription.ARGUMENT_LONG_LOG_LEVEL,
          CommandDescription.ARGUMENT_SHORT_LOG_LEVEL),
          CommandDescription.DESCRIPTION_CONTEXT_LOG_LEVEL
      )
      .withRequiredArg()
      .describedAs(CommandDescription.DESCRIPTION_ARGUMENT_LOG_LEVEL)
      .withValuesConvertedBy(new LogLevelValueConverter())
      .defaultsTo(Level.WARN);
}

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-sparql-ext

.acceptsAll(Arrays.asList("q", "quote"), "CSV field quote character")
.withOptionalArg()
.withValuesConvertedBy(new ValueConverterCharacter())
.acceptsAll(Arrays.asList("d", "delimiter"), "CSV field delimiter")
.withRequiredArg()
.withValuesConvertedBy(new ValueConverterCharacter())
.defaultsTo(defaultCsvFormat.getDelimiter())
.withValuesConvertedBy(new ValueConverterCharacter())

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

.acceptsAll(Arrays.asList("q", "quote"), "CSV field quote character")
.withOptionalArg()
.withValuesConvertedBy(new ValueConverterCharacter())
.acceptsAll(Arrays.asList("d", "delimiter"), "CSV field delimiter")
.withRequiredArg()
.withValuesConvertedBy(new ValueConverterCharacter())
.defaultsTo(defaultCsvFormat.getDelimiter())
.withValuesConvertedBy(new ValueConverterCharacter())

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

Elasticsearch() {
  super("starts elasticsearch", () -> {}); // we configure logging later so we override the base class from configuring logging
  versionOption = parser.acceptsAll(Arrays.asList("V", "version"),
    "Prints elasticsearch version information and exits");
  daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
    "Starts Elasticsearch in the background")
    .availableUnless(versionOption);
  pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
    "Creates a pid file in the specified path on start")
    .availableUnless(versionOption)
    .withRequiredArg()
    .withValuesConvertedBy(new PathConverter());
  quietOption = parser.acceptsAll(Arrays.asList("q", "quiet"),
    "Turns off standard output/error streams logging in console")
    .availableUnless(versionOption)
    .availableUnless(daemonizeOption);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

Elasticsearch() {
  super("starts elasticsearch");
  versionOption = parser.acceptsAll(Arrays.asList("V", "version"),
    "Prints elasticsearch version information and exits");
  daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
    "Starts Elasticsearch in the background")
    .availableUnless(versionOption);
  pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
    "Creates a pid file in the specified path on start")
    .availableUnless(versionOption)
    .withRequiredArg()
    .withValuesConvertedBy(new PathConverter());
  quietOption = parser.acceptsAll(Arrays.asList("q", "quiet"),
    "Turns off standard ouput/error streams logging in console")
    .availableUnless(versionOption)
    .availableUnless(daemonizeOption);
}

代码示例来源:origin: apache/servicemix-bundles

Elasticsearch() {
  super("starts elasticsearch", () -> {}); // we configure logging later so we override the base class from configuring logging
  versionOption = parser.acceptsAll(Arrays.asList("V", "version"),
    "Prints elasticsearch version information and exits");
  daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
    "Starts Elasticsearch in the background")
    .availableUnless(versionOption);
  pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
    "Creates a pid file in the specified path on start")
    .availableUnless(versionOption)
    .withRequiredArg()
    .withValuesConvertedBy(new PathConverter());
  quietOption = parser.acceptsAll(Arrays.asList("q", "quiet"),
    "Turns off standard output/error streams logging in console")
    .availableUnless(versionOption)
    .availableUnless(daemonizeOption);
}

代码示例来源:origin: cpw/modlauncher

void processArguments(Environment env, Consumer<OptionParser> parserConsumer, BiConsumer<OptionSet, BiFunction<String, OptionSet, ITransformationService.OptionResult>> resultConsumer) {
  final OptionParser parser = new OptionParser();
  parser.allowsUnrecognizedOptions();
  profileOption = parser.accepts("version", "The version we launched with").withRequiredArg();
  gameDirOption = parser.accepts("gameDir", "Alternative game directory").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.DIRECTORY_EXISTING));
  assetsDirOption = parser.accepts("assetsDir", "Assets directory").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.DIRECTORY_EXISTING));
  minecraftJarOption = parser.accepts("minecraftJar", "Path to minecraft jar").withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.READABLE)).withValuesSeparatedBy(',');
  launchTarget = parser.accepts("launchTarget", "LauncherService target to launch").withRequiredArg();
  parserConsumer.accept(parser);
  nonOption = parser.nonOptions();
  this.optionSet = parser.parse(this.args);
  env.computePropertyIfAbsent(IEnvironment.Keys.VERSION.get(), s -> this.optionSet.valueOf(profileOption));
  env.computePropertyIfAbsent(IEnvironment.Keys.GAMEDIR.get(), f -> this.optionSet.valueOf(gameDirOption));
  env.computePropertyIfAbsent(IEnvironment.Keys.ASSETSDIR.get(), f -> this.optionSet.valueOf(assetsDirOption));
  env.computePropertyIfAbsent(IEnvironment.Keys.LAUNCHTARGET.get(), f -> this.optionSet.valueOf(launchTarget));
  resultConsumer.accept(this.optionSet, this::optionResults);
}

代码示例来源:origin: org.broadinstitute/barclay

OptionSpecBuilder bld = parser.acceptsAll(arg.getNames(), arg.doc);
if (arg.isFlag()) {
  bld.withOptionalArg().withValuesConvertedBy(new StrictBooleanConverter());
} else {
  bld.withRequiredArg();

代码示例来源:origin: NGDATA/hbase-indexer

+ " of update, use an empty value to remove a key: -cp solr.collection=")
.withRequiredArg()
.withValuesConvertedBy(new StringPairConverter())
.describedAs("key=value");
    + LifecycleState.ACTIVE + ", " + LifecycleState.DELETE_REQUESTED)
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<LifecycleState>(LifecycleState.class))
.defaultsTo(LifecycleState.DEFAULT)
.describedAs("state");
    + ", " + IncrementalIndexingState.DO_NOT_SUBSCRIBE)
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<IncrementalIndexingState>(IncrementalIndexingState.class))
.defaultsTo(IncrementalIndexingState.DEFAULT)
.describedAs("state");
    + "\"direct write\" mode (scanning over all records and sending the results to a live solr cluster)."))
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<BatchIndexingState>(BatchIndexingState.class))
.defaultsTo(BatchIndexingState.DEFAULT)
.describedAs("state");

代码示例来源:origin: com.ngdata/hbase-indexer-cli

+ " of update, use an empty value to remove a key: -cp solr.collection=")
.withRequiredArg()
.withValuesConvertedBy(new StringPairConverter())
.describedAs("key=value");
    + LifecycleState.ACTIVE + ", " + LifecycleState.DELETE_REQUESTED)
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<LifecycleState>(LifecycleState.class))
.defaultsTo(LifecycleState.DEFAULT)
.describedAs("state");
    + ", " + IncrementalIndexingState.DO_NOT_SUBSCRIBE)
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<IncrementalIndexingState>(IncrementalIndexingState.class))
.defaultsTo(IncrementalIndexingState.DEFAULT)
.describedAs("state");
    + "\"direct write\" mode (scanning over all records and sending the results to a live solr cluster)."))
.withRequiredArg()
.withValuesConvertedBy(new EnumConverter<BatchIndexingState>(BatchIndexingState.class))
.defaultsTo(BatchIndexingState.DEFAULT)
.describedAs("state");

相关文章