use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.
the class AtlasDbCliCommand method getOptionTypesForCommandMetadata.
@VisibleForTesting
static Map<String, OptionType> getOptionTypesForCommandMetadata(CommandMetadata subCommand) {
Map<String, OptionType> optionTypes = new HashMap<>();
List<OptionMetadata> commandOptions = ImmutableList.<OptionMetadata>builder().addAll(subCommand.getCommandOptions()).addAll(subCommand.getGroupOptions()).addAll(subCommand.getGlobalOptions()).build();
for (OptionMetadata option : commandOptions) {
if (option.isHidden()) {
continue;
}
List<String> sortedOptions = option.getOptions().stream().sorted((first, second) -> Integer.compareUnsigned(first.length(), second.length())).collect(Collectors.toList());
String longOption = Iterables.getLast(sortedOptions);
optionTypes.put(longOption, option.getOptionType());
}
return ImmutableMap.copyOf(optionTypes);
}
use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.
the class AtlasDbCliCommand method addOptionToParser.
@VisibleForTesting
static void addOptionToParser(Subparser parser, OptionMetadata option) {
if (option.isHidden()) {
return;
}
List<String> sortedOptions = option.getOptions().stream().sorted((first, second) -> Integer.compareUnsigned(first.length(), second.length())).collect(Collectors.toList());
String longOption = Iterables.getLast(sortedOptions);
Argument arg = parser.addArgument(sortedOptions.toArray(new String[] {})).required(option.isRequired()).help(option.getDescription()).dest(longOption);
if (option.getArity() == 0) {
arg.action(Arguments.storeConst());
arg.setConst(AtlasDbCommandUtils.ZERO_ARITY_ARG_CONSTANT);
} else {
arg.nargs(option.getArity());
}
}
use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.
the class AtlasDbCliCommand method addCommandToParser.
private void addCommandToParser(Subparser subparser, CommandMetadata subCommand, List<String> commandRoot) {
Subparser parser = subparser.addSubparsers().addParser(subCommand.getName()).description(subCommand.getDescription()).setDefault(COMMAND_NAME_ATTR, ImmutableList.builder().addAll(commandRoot).add(subCommand.getName()).build());
for (OptionMetadata option : subCommand.getAllOptions()) {
addOptionToParser(parser, option);
}
super.configure(parser);
}
use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.
the class AtlasDbCliCommandTest method nargsIsSetOnArgumentWhenThereAreExpectedArguments.
@Test
public void nargsIsSetOnArgumentWhenThereAreExpectedArguments() {
int expectedArity = 5;
OptionMetadata metadata = new OptionMetadata(OptionType.COMMAND, ImmutableSet.of("arg"), "name", "description", expectedArity, false, false, ImmutableSet.of(), getOptionFields());
Argument argument = getArgumentMockFromAddOptionToParser(metadata, "arg");
verify(argument).nargs(5);
}
use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.
the class AtlasDbCliCommandTest method destIsSetToLongestArg.
@Test
public void destIsSetToLongestArg() {
String expectedDest = "long string here";
OptionMetadata metadata = new OptionMetadata(OptionType.COMMAND, ImmutableSet.of("arg", "longer arg", expectedDest), "name", "description", 0, false, false, ImmutableSet.of(), getOptionFields());
Argument argument = getArgumentMockFromAddOptionToParser(metadata, "arg", "longer arg", expectedDest);
verify(argument).dest(expectedDest);
}
Aggregations