Skip to content

Commit

Permalink
Fix for WFCORE-2283. Completion for alternatives,requires and required
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Nov 15, 2017
1 parent 45a9a8b commit 1bc11e2
Show file tree
Hide file tree
Showing 9 changed files with 1,427 additions and 443 deletions.
9 changes: 9 additions & 0 deletions cli/src/main/java/org/jboss/as/cli/CommandArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public interface CommandArgument {
*/
String getFullName();

/**
* The name can contain some tags to advertise status (e.g.: required).
*
* @return The default name of the argument with optional tags.
*/
default String getDecoratedName() {
return getFullName();
}

/**
* Short name of the argument if exists.
* @return short name of the argument or null if the short name doesn't exist.
Expand Down
2 changes: 2 additions & 0 deletions cli/src/main/java/org/jboss/as/cli/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class Util {
public static final String ADDRESS = "address";
public static final String ALLOWED = "allowed";
public static final String ALLOW_RESOURCE_SERVICE_RESTART = "allow-resource-service-restart";
public static final String ALTERNATIVES = "alternatives";
public static final String ARCHIVE = "archive";
public static final String ATTACHED_STREAMS = "attached-streams";
public static final String ATTRIBUTES = "attributes";
Expand Down Expand Up @@ -163,6 +164,7 @@ public class Util {
public static final String REPLY_PROPERTIES = "reply-properties";
public static final String REQUEST_PROPERTIES = "request-properties";
public static final String REQUIRED = "required";
public static final String REQUIRES = "requires";
public static final String RESOLVE_EXPRESSIONS = "resolve-expressions";
public static final String RESPONSE_HEADERS = "response-headers";
public static final String RESTART = "restart";
Expand Down
64 changes: 38 additions & 26 deletions cli/src/main/java/org/jboss/as/cli/impl/ValueTypeCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jboss.as.cli.handlers.FilenameTabCompleter;
import org.jboss.as.cli.operation.OperationRequestAddress;
import org.jboss.as.cli.operation.impl.CapabilityReferenceCompleter;
import org.jboss.as.cli.operation.impl.DefaultOperationCandidatesProvider.PropertyVisibility;
import org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress;
import org.jboss.as.cli.parsing.CharacterHandler;
import org.jboss.as.cli.parsing.DefaultParsingState;
Expand All @@ -48,6 +49,7 @@
import org.jboss.as.cli.parsing.arguments.ArgumentValueState;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;
import org.jboss.logging.Logger;

/**
Expand Down Expand Up @@ -592,12 +594,32 @@ public Collection<String> getCandidates(ModelNode propDescr) {
// Retrieve the last property (if any)
Instance.Property last = currentInstance.getLastProperty();

Set<String> presentProperties = new HashSet<>();
for (Instance.Property p : currentInstance.properties) {
if (p.value != null) {
presentProperties.add(p.name);
}
}
// The user typed the start of a property name
String nameChunk = null;
if (last != null) {
if (!lastEnteredState.equals(EqualsState.ID)) {
if (last.value == null) {
nameChunk = last.name;
}
}
}
List<Property> properties = isObject(propType)
? propType.asPropertyList() : Collections.emptyList();
PropertyVisibility visibility = new PropertyVisibility(properties,
presentProperties, nameChunk);

// On list separator, or when no property exists,
// complete with the next item in the list or the next property
// inside an Object
if (lastEnteredState.equals(ListItemSeparatorState.ID)
|| last == null) {
return completeNewProperty(propType);
return completeNewProperty(propType, visibility);
}

// At this point, we have a property that is not terminated.
Expand Down Expand Up @@ -630,7 +652,7 @@ public Collection<String> getCandidates(ModelNode propDescr) {
// If the value is complete, we could return '}' or ','if the object is
// complete.
if (complete) {
return getCompletedValueCandidates(propType);
return getCompletedValueCandidates(propType, visibility);
} else {
return candidates;
}
Expand All @@ -645,12 +667,12 @@ public Collection<String> getCandidates(ModelNode propDescr) {
return Collections.emptyList();
}
if (last.value.isComplete()) { // a property of type List or Object that is complete
return getCompletedValueCandidates(propType);
return getCompletedValueCandidates(propType, visibility);
} else {
List<String> candidates = new ArrayList<>();
boolean complete = getSimpleValues(propType, last.name, last.value.asString(), candidates);
if (complete) {
return getCompletedValueCandidates(propType);
return getCompletedValueCandidates(propType, visibility);
} else {
return candidates;
}
Expand Down Expand Up @@ -697,11 +719,8 @@ public Collection<String> getCandidates(ModelNode propDescr) {
if (!isObject(propType)) {
return Collections.<String>emptyList();
}
for (String p : propType.keys()) {
if (p.startsWith(last.name) && !currentInstance.contains(p)) {
candidates.add(p);
}
}
visibility.addCandidates(candidates);

// Inline the equals.
if (candidates.size() == 1) {
if (last.name.equals(candidates.get(0))) {
Expand Down Expand Up @@ -757,20 +776,15 @@ private List<String> getCapabilitiesListContent(Instance.Property last) {
return candidates;
}

private List<String> getCompletedValueCandidates(ModelNode propType) {
private List<String> getCompletedValueCandidates(ModelNode propType, PropertyVisibility visibility) {
// In this case we need to reach the end of the stream and add separator.
valLength = buffer.length() - lastStateIndex;
// Do we have some properties to propose?
if (propType.getType() == ModelType.OBJECT) {
final List<String> props = new ArrayList<>(propType.keys());
// Remove the properties already present
for (Instance.Property p : currentInstance.properties) {
props.remove(p.name);
}
if (props.isEmpty()) {
return Collections.singletonList("}");
} else {
if (visibility.hasMore()) {
return Collections.singletonList(",");
} else {
return Collections.singletonList("}");
}
} else {
return Collections.emptyList();
Expand Down Expand Up @@ -827,7 +841,8 @@ private boolean getSimpleValues(ModelNode propType, String name,
}

// Completion for a new property
private Collection<String> completeNewProperty(ModelNode propType) {
private Collection<String> completeNewProperty(ModelNode propType,
PropertyVisibility visibility) {
if (currentInstance instanceof ListInstance) {
// This is inside a list
try {
Expand Down Expand Up @@ -876,15 +891,12 @@ private Collection<String> completeNewProperty(ModelNode propType) {
// or a Map<String, 'propType'>;
if (propType.getType() == ModelType.OBJECT) {
// This is inside an instance.
final List<String> candidates = new ArrayList<>(propType.keys());
// Remove the properties already present
for (Instance.Property p : currentInstance.properties) {
candidates.remove(p.name);
}
if (candidates.isEmpty()) {
// Retrieve all required.
final List<String> candidates = new ArrayList<>();
if (propType.keys().isEmpty()) {
candidates.add("}");
} else {
Collections.sort(candidates);
visibility.addCandidates(candidates);
}
return candidates;
} else {
Expand Down

0 comments on commit 1bc11e2

Please sign in to comment.