use of org.springframework.shell.core.annotation.CliOption in project geode by apache.
the class Helper method getHelp.
/**
* returns a short description and help string of the command if annotations is null or returns a
* details description of the command with the syntax and parameter description
*/
HelpBlock getHelp(CliCommand cliCommand, Annotation[][] annotations, Class<?>[] parameterTypes) {
String commandName = cliCommand.value()[0];
boolean isAvailable = isAvailable(commandName);
if (annotations == null && parameterTypes == null) {
String available = isAvailable ? AVAILABLE : NOT_AVAILABLE;
HelpBlock help = new HelpBlock(commandName + " (" + available + ")");
help.addChild(new HelpBlock(cliCommand.help()));
return help;
}
HelpBlock root = new HelpBlock();
// First we will have the block for NAME of the command
HelpBlock name = new HelpBlock(NAME_NAME);
name.addChild(new HelpBlock(commandName));
root.addChild(name);
// add the availability flag
HelpBlock availability = new HelpBlock(IS_AVAILABLE_NAME);
availability.addChild(new HelpBlock(isAvailable + ""));
root.addChild(availability);
// Now add synonyms if any
String[] allNames = cliCommand.value();
if (allNames.length > 1) {
HelpBlock synonyms = new HelpBlock(SYNONYMS_NAME);
for (int i = 1; i < allNames.length; i++) {
synonyms.addChild(new HelpBlock(allNames[i]));
}
root.addChild(synonyms);
}
// Now comes the turn to display synopsis if any
if (StringUtils.isNotBlank(cliCommand.help())) {
HelpBlock synopsis = new HelpBlock(SYNOPSIS_NAME);
synopsis.addChild(new HelpBlock(cliCommand.help()));
root.addChild(synopsis);
}
// Now display the syntax for the command
HelpBlock syntaxBlock = new HelpBlock(SYNTAX_NAME);
String syntax = getSyntaxString(commandName, annotations, parameterTypes);
syntaxBlock.addChild(new HelpBlock(syntax));
root.addChild(syntaxBlock);
// Detailed description of all the Options
if (annotations.length > 0) {
HelpBlock options = new HelpBlock(OPTIONS_NAME);
for (int i = 0; i < annotations.length; i++) {
CliOption cliOption = getAnnotation(annotations[i], CliOption.class);
HelpBlock optionNode = getOptionDetail(cliOption);
options.addChild(optionNode);
}
root.addChild(options);
}
return root;
}
use of org.springframework.shell.core.annotation.CliOption in project geode by apache.
the class LuceneIndexCommands method createIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX, help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_CREATE_INDEX__REGION_HELP) final String regionPath, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD_HELP) final String[] fields, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER, help = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER_HELP) final String[] analyzers) {
Result result;
XmlEntity xmlEntity = null;
this.securityService.authorizeRegionManage(regionPath);
try {
final InternalCache cache = getCache();
// trim fields for any leading trailing spaces.
String[] trimmedFields = Arrays.stream(fields).map(field -> field.trim()).toArray(size -> new String[size]);
LuceneIndexInfo indexInfo = new LuceneIndexInfo(indexName, regionPath, trimmedFields, analyzers);
final ResultCollector<?, ?> rc = this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();
final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
for (final CliFunctionResult cliFunctionResult : funcResults) {
tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
if (cliFunctionResult.isSuccessful()) {
tabularResult.accumulate("Status", "Successfully created lucene index");
// if (xmlEntity == null) {
// xmlEntity = cliFunctionResult.getXmlEntity();
// }
} else {
tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
}
}
result = ResultBuilder.buildResult(tabularResult);
} catch (IllegalArgumentException iae) {
LogWrapper.getInstance().info(iae.getMessage());
result = ResultBuilder.createUserErrorResult(iae.getMessage());
} catch (CommandResultException crex) {
result = crex.getResult();
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.springframework.shell.core.annotation.CliOption in project geode by apache.
the class Helper method getSyntaxString.
String getSyntaxString(String commandName, Annotation[][] annotations, Class[] parameterTypes) {
StringBuffer buffer = new StringBuffer();
buffer.append(commandName);
for (int i = 0; i < annotations.length; i++) {
CliOption cliOption = getAnnotation(annotations[i], CliOption.class);
String optionString = getOptionString(cliOption, parameterTypes[i]);
if (cliOption.mandatory()) {
buffer.append(" ").append(optionString);
} else {
buffer.append(" [").append(optionString).append("]");
}
}
return buffer.toString();
}
Aggregations