com.beust.jcommander.IStringConverterFactory Java Examples

The following examples show how to use com.beust.jcommander.IStringConverterFactory. 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: CommandLine.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
private static JCommander prepareParser(CliOptions options) {
  JCommander.Builder builder = JCommander.newBuilder()
      .programName(SchedulerMain.class.getName());

  builder.addConverterFactory(new IStringConverterFactory() {
    private Map<Class<?>, Class<? extends IStringConverter<?>>> classConverters =
        ImmutableMap.<Class<?>, Class<? extends IStringConverter<?>>>builder()
            .put(Class.class, ClassConverter.class)
            .put(DataAmount.class, DataAmountConverter.class)
            .put(DockerParameter.class, DockerParameterConverter.class)
            .put(InetSocketAddress.class, InetSocketAddressConverter.class)
            .put(KerberosPrincipal.class, KerberosPrincipalConverter.class)
            .put(TimeAmount.class, TimeAmountConverter.class)
            .put(Volume.class, VolumeConverter.class)
            .build();

    @SuppressWarnings("unchecked")
    @Override
    public <T> Class<? extends IStringConverter<T>> getConverter(Class<T> forType) {
      return (Class<IStringConverter<T>>) classConverters.get(forType);
    }
  });

  builder.addObject(getOptionsObjects(options));
  return builder.build();
}
 
Example #2
Source File: RecoveryTool.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
private static JCommander configure(Options options, String... args) {
  JCommander.Builder builder = JCommander.newBuilder().programName(RecoveryTool.class.getName());
  builder.addConverterFactory(new IStringConverterFactory() {
    private Map<Class<?>, Class<? extends IStringConverter<?>>> classConverters =
        ImmutableMap.<Class<?>, Class<? extends IStringConverter<?>>>builder()
            .put(DataAmount.class, DataAmountConverter.class)
            .put(InetSocketAddress.class, InetSocketAddressConverter.class)
            .put(TimeAmount.class, TimeAmountConverter.class)
            .build();

    @SuppressWarnings("unchecked")
    @Override
    public <T> Class<? extends IStringConverter<T>> getConverter(Class<T> forType) {
      return (Class<IStringConverter<T>>) classConverters.get(forType);
    }
  });

  builder.addObject(options);
  for (Endpoint endpoint : Endpoint.values()) {
    endpoint.impl.getOptions().forEach(builder::addObject);
  }

  JCommander parser = builder.build();
  parser.parse(args);
  return parser;
}