use of org.aesh.command.impl.internal.ProcessedOption in project wildfly-core by wildfly.
the class HelpSupport method printOptions.
private static String printOptions(List<ProcessedOption> opts, ProcessedOption arg, boolean isOperation) {
int width = 80;
StringBuilder sb = new StringBuilder();
if (!opts.isEmpty()) {
sb.append(Config.getLineSeparator()).append("OPTIONS").append(Config.getLineSeparator());
sb.append(Config.getLineSeparator());
}
// Retrieve the tab length
int maxOptionName = 0;
for (ProcessedOption o : opts) {
String name = createOptionName(o.name(), o.name().length(), o.shortName(), isOperation);
if (name.length() > maxOptionName) {
maxOptionName = name.length();
}
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < maxOptionName; i++) {
builder.append(" ");
}
String tab = builder.toString();
for (ProcessedOption o : opts) {
String name = createOptionName(o.name(), maxOptionName, o.shortName(), isOperation);
sb.append(name);
sb.append(HelpSupport.splitAndFormat(o.description(), width, "", name.length(), tab));
sb.append(Config.getLineSeparator());
}
if (arg != null) {
sb.append(Config.getLineSeparator()).append("ARGUMENT").append(Config.getLineSeparator());
sb.append(Config.getLineSeparator());
sb.append(HelpSupport.splitAndFormat(arg.description(), width, HelpSupport.TAB, 0, HelpSupport.TAB));
}
return sb.toString();
}
use of org.aesh.command.impl.internal.ProcessedOption in project wildfly-core by wildfly.
the class SynopsisGenerator method buildOption.
private static void buildOption(Map<String, SynopsisOption> options, boolean isArgument, ProcessedOption opt, List<ProcessedOption> opts, ProcessedOption arg, boolean domain) {
List<ProcessedOption> expected = retrieveExpected(opt.activator(), opts, isArgument ? null : arg, domain);
SynopsisOption synopsisOpt = null;
if (isArgument) {
synopsisOpt = new SynopsisOption();
synopsisOpt.option = arg;
options.put("", synopsisOpt);
} else {
synopsisOpt = options.get(opt.name());
if (synopsisOpt == null) {
synopsisOpt = new SynopsisOption();
synopsisOpt.option = opt;
options.put(opt.name(), synopsisOpt);
}
}
for (ProcessedOption e : expected) {
SynopsisOption depDep = options.get(e.name());
if (depDep == null) {
depDep = new SynopsisOption();
depDep.option = e;
options.put(e.name(), depDep);
}
synopsisOpt.dependsOn.add(depDep);
depDep.dependedBy.add(synopsisOpt);
}
List<ProcessedOption> oneOfExpected = retrieveOneOfExpected(opt.activator(), opts, arg, domain);
// First dependency is treated as a nominal one.
int i = 0;
for (ProcessedOption e : oneOfExpected) {
SynopsisOption depDep = options.get(e.name());
if (depDep == null) {
depDep = new SynopsisOption();
depDep.option = e;
options.put(e.name(), depDep);
}
if (duplicateOneOfDependencies) {
if (i == 0) {
synopsisOpt.dependsOn.add(depDep);
depDep.dependedBy.add(synopsisOpt);
i += 1;
} else {
SynopsisOption o = new SynopsisOption("oneof-" + e.name());
o.option = opt;
o.dependsOn.add(depDep);
depDep.dependedBy.add(o);
options.put("oneof-" + e.name(), o);
}
} else {
depDep.dependedByOneOff.add(synopsisOpt);
}
}
List<ProcessedOption> notExpected = retrieveNotExpected(opt.activator(), opts, arg, domain);
for (ProcessedOption e : notExpected) {
SynopsisOption depDep = options.get(e.name());
if (depDep == null) {
depDep = new SynopsisOption();
depDep.option = e;
options.put(e.name(), depDep);
}
synopsisOpt.conflictWith.add(depDep);
depDep.conflictWith.add(synopsisOpt);
}
}
use of org.aesh.command.impl.internal.ProcessedOption in project wildfly-core by wildfly.
the class HelpSupport method printHelp.
public static String printHelp(CommandContext ctx, ModelNode mn, OperationRequestAddress address) {
try {
// Build a ProcessedCommand from the ModelNode
String commandName = mn.get("operation-name").asString();
String desc = mn.get(Util.DESCRIPTION).asString();
desc += Config.getLineSeparator() + Config.getLineSeparator() + "NB: to retrieve operation full description call the following operation: " + buildAddress(address) + ":" + Util.READ_OPERATION_DESCRIPTION + "(name=" + commandName + ")";
ModelNode props = mn.get(Util.REQUEST_PROPERTIES);
ProcessedCommand pcommand = ProcessedCommandBuilder.builder().name(commandName).description(desc).create();
for (String prop : props.keys()) {
ModelNode p = props.get(prop);
Class<?> clazz = getClassFromType(getAdaptedArgumentType(p));
boolean required = p.hasDefined(Util.REQUIRED) ? p.get(Util.REQUIRED).asBoolean() : false;
ProcessedOption opt = ProcessedOptionBuilder.builder().name(prop).required(required).hasValue(true).description(buildOperationArgumentDescription(p)).type(clazz).build();
pcommand.addOption(opt);
}
String content = getCommandHelp(null, Collections.emptyList(), null, Collections.emptyList(), pcommand.getOptions(), pcommand, null, commandName, pcommand, true);
if (mn.hasDefined("reply-properties")) {
ModelNode reply = mn.get("reply-properties");
// Add response value
StringBuilder builder = new StringBuilder();
builder.append(content);
builder.append("RETURN VALUE");
builder.append(Config.getLineSeparator());
builder.append(Config.getLineSeparator());
if (reply.hasDefined("type")) {
builder.append(reply.get("type").asString()).append(". ");
}
if (reply.hasDefined("description")) {
builder.append(reply.get("description").asString());
}
builder.append(Config.getLineSeparator());
builder.append(Config.getLineSeparator());
content = builder.toString();
}
return content;
} catch (Exception ex) {
// XXX OK.
return null;
}
}
use of org.aesh.command.impl.internal.ProcessedOption in project galleon by wildfly.
the class AbstractDynamicCommand method validateOptions.
private void validateOptions(PmCommandInvocation invoc) throws CommandExecutionException {
// Check validity of provided options
Set<String> providedOptions = getValues().keySet();
List<ProcessedOption> sOptions = cmd.getOptions(false);
if (optimizeRetrieval) {
// check values
for (String o : providedOptions) {
for (ProcessedOption opt : sOptions) {
if (opt.name().equals(o)) {
String val = (String) getValue(opt.name());
if (opt.hasValue() && (val == null || val.isEmpty())) {
throw new CommandExecutionException("Option --" + opt.name() + " was specified, but no value was given");
}
}
}
}
// check required
for (ProcessedOption opt : sOptions) {
if (opt.isRequired() && !providedOptions.contains(opt.name())) {
throw new CommandExecutionException("Option --" + opt.name() + " is required for this command.");
}
}
} else {
List<ProcessedOption> dOptions = cmd.getOptions(true);
for (String o : providedOptions) {
boolean found = false;
if (!ARGUMENT_NAME.equals(o)) {
// first find in static options
for (ProcessedOption opt : sOptions) {
if (opt.name().equals(o)) {
found = true;
break;
}
}
if (!found) {
// then in dynamic ones
for (ProcessedOption opt : dOptions) {
if (opt.name().equals(o)) {
found = true;
break;
}
}
if (!found) {
throw new CommandExecutionException("Unknown option --" + o);
}
}
}
}
}
doValidateOptions(invoc);
}
use of org.aesh.command.impl.internal.ProcessedOption in project galleon by wildfly.
the class UpdateCommand method getOtherOptions.
@Override
protected List<ProcessedOption> getOtherOptions() throws OptionParserException {
List<ProcessedOption> options = new ArrayList<>();
ProcessedOption includeAll = ProcessedOptionBuilder.builder().name(ALL_DEPENDENCIES_OPTION_NAME).hasValue(false).type(Boolean.class).optionType(OptionType.BOOLEAN).description(HelpDescriptions.UPDATE_DEPENDENCIES).completer(FileOptionCompleter.class).activator(AllDepsOptionActivator.class).required(false).build();
options.add(includeAll);
ProcessedOption yes = ProcessedOptionBuilder.builder().name(YES_OPTION_NAME).hasValue(false).type(Boolean.class).optionType(OptionType.BOOLEAN).description(HelpDescriptions.UPDATE_NO_CONFIRMATION).completer(FileOptionCompleter.class).required(false).shortName('y').build();
options.add(yes);
ProcessedOption fp = ProcessedOptionBuilder.builder().name(FP_OPTION_NAME).hasValue(true).type(String.class).optionType(OptionType.NORMAL).description(HelpDescriptions.UPDATE_FP).required(false).completer(InstalledProducerCompleter.class).activator(FPOptionActivator.class).build();
options.add(fp);
return options;
}
Aggregations