List of usage examples for org.apache.commons.cli2.validation EnumValidator EnumValidator
public EnumValidator(final Set values)
From source file:br.edu.ifpb.pos.command.Commands.java
public Group createOptions() { Option help = obuilder.withLongName("help").withDescription("Ajuda para o usurio").create(); ///*w w w . j a v a2s. c o m*/ Set<String> typeEntity = new TreeSet(); typeEntity.add("json_person"); typeEntity.add("json_user"); EnumValidator enumValidator = new EnumValidator(typeEntity); Option type = obuilder .withLongName("type").withDescription("Tipo de Objeto a ser salvo").withArgument(abuilder .withMaximum(1).withMinimum(1).withName("type").withValidator(enumValidator).create()) .create(); // Group groupType = gbuilder.withOption(type).withMaximum(1).withMinimum(1).withRequired(true).create(); // Argument argument = abuilder.withName("json_object").withMaximum(1).withMinimum(1).create(); // Option insert = obuilder.withLongName("insert") .withDescription("Insere um novo objeto em formarto JSON de acordo com os atributos da entidade") .withChildren(groupType).withArgument(argument).create(); Option delete = obuilder.withLongName("delete") .withDescription("Exclui um objeto passando a chave da entidade nesse formato: {\"key\": value}") .withArgument(argument).withChildren(groupType).create(); Option update = obuilder.withLongName("update").withDescription( "Atualiza um objeto em formarto JSON de acordo com esse formato: {\"key\": value, outros parametros...}") .withArgument(argument).withChildren(groupType).create(); Group crudGroup = gbuilder.withOption(update).withOption(insert).withOption(delete).withRequired(true) .create(); Option select = obuilder.withLongName("select") .withDescription("Visualiza um objeto passando a chave da entidade nesse formato: {\"key\": value}") .withArgument(argument).withChildren(groupType).create(); Group group = gbuilder.withOption(help).withOption(crudGroup).withOption(select).create(); return group; }
From source file:org.pharmgkb.util.CliHelper.java
/** * Add a required option that takes an enumerated argument. *//* w ww . ja va2s . co m*/ public void addOption(String shortName, String longName, String description, String argName, Set<String> arguments, boolean isRequired) { if (shortName.equals("h") || shortName.equals("v")) { throw new IllegalArgumentException("-h and -v are reserved arguments"); } m_groupBuilder = m_groupBuilder.withOption( m_optBuilder.withDescription(description).withLongName(longName).withShortName(shortName) .withArgument(m_argBuilder.withName(argName).withMinimum(1).withMaximum(1) .withValidator(new EnumValidator(arguments)).create()) .withRequired(isRequired).create()); }