use of org.jboss.as.cli.CommandArgument in project wildfly-core by wildfly.
the class ArgumentWithoutValue method canAppearNext.
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if (!access.isSatisfied(ctx)) {
return false;
}
ParsedCommandLine args = ctx.getParsedCommandLine();
if (exclusive) {
final Set<String> propertyNames = args.getPropertyNames();
if (propertyNames.isEmpty()) {
final List<String> values = args.getOtherProperties();
if (values.isEmpty()) {
return true;
}
if (index == -1) {
return false;
}
return !(index == 0 && values.size() == 1);
}
if (propertyNames.size() != 1) {
return false;
}
if (args.getLastParsedPropertyName() == null) {
return false;
}
final List<String> values = args.getOtherProperties();
if (!values.isEmpty()) {
return false;
}
// The argument is already there, don't add it.
if (fullName.equals(args.getLastParsedPropertyName())) {
return false;
}
return fullName.startsWith(args.getLastParsedPropertyName()) || (shortName != null && shortName.startsWith(args.getLastParsedPropertyName()));
}
if (isPresent(args)) {
// An argument without value has no value
return false;
}
for (CommandArgument arg : cantAppearAfter) {
if (arg.isPresent(args)) {
return false;
}
}
if (requiredPreceding != null) {
for (CommandArgument arg : requiredPreceding) {
if (arg.isPresent(args)) {
return true;
}
}
return false;
}
return true;
}
use of org.jboss.as.cli.CommandArgument in project wildfly-core by wildfly.
the class OperationRequestCompleter method completeProperties.
private int completeProperties(CommandContext ctx, ParsedCommandLine parsedCmd, OperationCandidatesProvider candidatesProvider, String buffer, List<String> candidates) {
// Invalid case of no operation name provided.
if (!parsedCmd.hasOperationName()) {
return -1;
}
// Retrieve all operation arguments from remote server.
final Collection<CommandArgument> allArgs = candidatesProvider.getProperties(ctx, parsedCmd.getOperationName(), parsedCmd.getAddress());
// No argument/option for this operation/command.
if (allArgs.isEmpty()) {
return completeNoProperties(parsedCmd, buffer, candidates);
}
// The lastcharacter typed is '!', we need a property name.
if (parsedCmd.endsOnNotOperator()) {
return completeImplicitValueProperties(ctx, buffer, allArgs, candidates);
}
// No properties have been already set.
if (!parsedCmd.hasProperties()) {
return completeNoPropertiesProvided(ctx, buffer, allArgs, candidates);
}
// We should complete at the end of the input.
int result = buffer.length();
// chunk is the last piece of text the user typed.
String chunk = null;
// a property/option value or an argument value.
if (!parsedCmd.endsOnPropertySeparator()) {
final String argName = parsedCmd.getLastParsedPropertyName();
final String argValue = parsedCmd.getLastParsedPropertyValue();
// Complete a value.
if (argValue != null || parsedCmd.endsOnPropertyValueSeparator()) {
result = parsedCmd.getLastChunkIndex();
if (parsedCmd.endsOnPropertyValueSeparator()) {
// it enters on '='
++result;
}
chunk = argValue;
CommandLineCompleter valueCompleter = null;
if (argName != null) {
// Retrieve the completer based on name
valueCompleter = getValueCompleter(ctx, allArgs, argName);
} else {
// retrieve the completer based on argument index.
valueCompleter = getValueCompleter(ctx, allArgs, parsedCmd.getOtherProperties().size() - 1);
}
// No value completer for this property.
if (valueCompleter == null) {
return completeNoValueCompleter(ctx, parsedCmd, allArgs, argName, buffer, candidates);
} else {
// Complete with a value Completer.
return completeWithValueCompleter(ctx, parsedCmd, allArgs, argName, buffer, candidates, chunk, result, valueCompleter);
}
} else {
// Will complete possibly a name.
chunk = argName;
// Name completion is inlined at the begining of the name, not at
// the end of the user input.
result = parsedCmd.getLastChunkIndex();
}
}
// unammed argument value (apply to commands only).
return completeArgumentValueAndPropertyNames(ctx, parsedCmd, allArgs, candidates, chunk, result);
}
use of org.jboss.as.cli.CommandArgument in project wildfly-core by wildfly.
the class OperationRequestCompleter method completeNoPropertiesProvided.
private int completeNoPropertiesProvided(CommandContext ctx, String buffer, Collection<CommandArgument> allArgs, List<String> candidates) {
try {
boolean needNeg = false;
for (CommandArgument arg : allArgs) {
if (arg.canAppearNext(ctx)) {
// In this case call the value completer.
if (arg.getIndex() >= 0) {
final CommandLineCompleter valCompl = arg.getValueCompleter();
if (valCompl != null) {
valCompl.complete(ctx, "", 0, candidates);
// Values have been added as candidate.
// If there are some options to propose, they will be mixed
// with the values. That only applies to commands.
}
} else {
candidates.add(arg.getDecoratedName());
// doesn't need a value (is a boolean).
if (!arg.isValueRequired()) {
needNeg = true;
}
}
}
}
if (needNeg) {
candidates.add(Util.NOT_OPERATOR);
}
Collections.sort(candidates);
return buffer.length();
} catch (CommandFormatException e) {
return -1;
}
}
Aggregations