use of io.airlift.airline.OptionType 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.OptionType in project atlasdb by palantir.
the class AtlasDbCliCommand method run.
@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
AtlasDbConfig cliConfiguration = AtlasDbCommandUtils.convertServerConfigToClientConfig(configuration.getAtlasDbConfig(), configuration.getAtlasDbRuntimeConfig());
Map<String, OptionType> optionTypes = getCliOptionTypes();
Map<String, Object> globalAttrs = Maps.filterKeys(namespace.getAttrs(), key -> optionTypes.get(key) == OptionType.GLOBAL);
Map<String, Object> groupAttrs = Maps.filterKeys(namespace.getAttrs(), key -> optionTypes.get(key) == OptionType.GROUP);
Map<String, Object> commandAttrs = Maps.filterKeys(namespace.getAttrs(), key -> optionTypes.get(key) == OptionType.COMMAND);
Iterable<String> groups = Iterables.limit(namespace.getList(COMMAND_NAME_ATTR), 1);
Iterable<String> commands = Iterables.skip(namespace.getList(COMMAND_NAME_ATTR), 1);
List<String> allArgs = ImmutableList.<String>builder().add("--inline-config").add(AtlasDbCommandUtils.serialiseConfiguration(cliConfiguration)).addAll(AtlasDbCommandUtils.gatherPassedInArguments(globalAttrs)).addAll(groups).addAll(AtlasDbCommandUtils.gatherPassedInArguments(groupAttrs)).addAll(commands).addAll(AtlasDbCommandUtils.gatherPassedInArguments(commandAttrs)).build();
try {
CLI.parse(allArgs).call();
} catch (Throwable e) {
log.error("Error running AtlasDB CLI", e);
throw e;
}
}
Aggregations