Skip to content

Commit

Permalink
Merge pull request wildfly#5415 from ChristinaDsl/WFCORE-4916
Browse files Browse the repository at this point in the history
[WFCORE-4916] Unclear attribute name completion for LIST type
  • Loading branch information
yersan authored Oct 4, 2023
2 parents 7463a5c + af1d297 commit fec6a97
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public Collection<String> getCandidates(ModelNode attrsDescr, boolean writeOnly)
candidateIndex += chunk.length();
}
candidates.add("[");
} else if (modelType.equals(ModelType.STRING) || modelType.equals(ModelType.INT) || modelType.equals(ModelType.BOOLEAN)){
if (candidates.isEmpty()) {
candidateIndex += chunk.length();
}
candidates.add("");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jboss.as.cli.parsing.StateParser.SubstitutedLine;
import org.jboss.logging.Logger;


/**
*
* @author Alexey Loubyansky
Expand Down Expand Up @@ -401,22 +400,24 @@ private int completeWithValueCompleter(CommandContext ctx, ParsedCommandLine par
// Implies a single candidate to inline, the value is complete.
// propose the property separator if more properties to come
// or the propertyListEnd if no more properties.
if (suggestionEqualsUserEntry(candidates, chunk, valueResult)) {
if (suggestionEqualsUserEntry(candidates, chunk, valueResult)|| areIncludedCandidatesForSpecificValueTypes(candidates)) {
final CommandLineFormat format = parsedCmd.getFormat();
if (format != null) {
for (CommandArgument arg : allArgs) {
try {
if (arg.canAppearNext(ctx)) {
candidates.set(0, "" + format.getPropertySeparator());
candidates.add("" + format.getPropertySeparator());
return buffer.length();
}
} catch (CommandFormatException e) {
return -1;
}
}
// inline the end of properties.
candidates.set(0, format.getPropertyListEnd());
// at the end of the input.
if((buffer.charAt(buffer.length() - 1))!='='){
candidates.add(format.getPropertyListEnd());
}
return buffer.length();
}
}
Expand Down Expand Up @@ -717,12 +718,26 @@ private boolean suggestionEqualsUserEntry(List<String> candidates, String chunk,
return false;
}

if (suggestionOffset > 0) {
if (suggestionOffset > 0 && candidates.get(0)!="") {
// user entry before suggestionOffset is always the same - compare only part after offset
return chunk.substring(suggestionOffset).equals(candidates.get(0));
} else {
return chunk.equals(candidates.get(0));
if(chunk.equals(candidates.get(0))){
candidates.clear();
return true;
}
return false;
}
}

boolean areIncludedCandidatesForSpecificValueTypes(List<String> candidates){
if(candidates.contains("[") || candidates.contains(".")){
return true;
}else if(candidates.contains("")){
candidates.remove("");
return true;
}
return false;
}

protected CommandLineCompleter getValueCompleter(CommandContext ctx, Iterable<CommandArgument> allArgs, final String argName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ protected List<CommandArgument> getPropertiesFromPropList(List<Property> propLis
if(ctx.getParsedCommandLine().getLastParsedPropertyValue() == null) {
radical = ctx.getParsedCommandLine().getLastParsedPropertyName();
//Check if the property is completely specified and is negated
if(ctx.getParsedCommandLine().isLastPropertyNegated()) {
if(ctx.getParsedCommandLine().isLastPropertyNegated() || radical!=null) {
for (Property prop : propList) {
if(radical.equals(prop.getName())){
radical = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void testMain() throws Exception {

candidates.clear();
i = completer.complete(null, "str", 0, candidates);
assertEquals(Arrays.asList("str2"), candidates);
assertEquals(Arrays.asList("", "str2"), candidates);
assertEquals(0, i);

candidates.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,10 +1140,12 @@ public void testCommandsCompletion2() throws Exception {
List<String> candidates = new ArrayList<>();
ctx.getDefaultCommandCompleter().complete(ctx, cmd,
cmd.length(), candidates);
assertTrue(candidates.toString(), candidates.size() == 1);
assertTrue(candidates.toString(), candidates.size() == 2);
assertTrue(candidates.toString(), candidates.contains(" "));
assertTrue(candidates.toString(), candidates.contains("namespaces"));
candidates = complete(ctx, cmd, false, cmd.length() - "name".length());
assertTrue(candidates.toString(), candidates.size() == 1);
candidates = complete(ctx, cmd, false, cmd.length());
assertTrue(candidates.toString(), candidates.size() == 2);
assertTrue(candidates.toString(), candidates.contains(" "));
assertTrue(candidates.toString(), candidates.contains("namespaces"));
}

Expand All @@ -1157,6 +1159,17 @@ public void testCommandsCompletion2() throws Exception {
assertTrue(candidates.toString(), candidates.isEmpty());
}

{
String cmd = "read-attribute management-minor-version";
List<String> candidates = new ArrayList<>();
ctx.getDefaultCommandCompleter().complete(ctx, cmd,
cmd.length(), candidates);
assertTrue(candidates.toString(), candidates.size() == 1);
assertTrue(candidates.toString(), candidates.contains(" "));
candidates = complete(ctx, cmd, false, cmd.length());
assertTrue(candidates.toString(), candidates.contains(" "));
}

{
String cmd = "read-operation --node";
List<String> candidates = new ArrayList<>();
Expand Down

0 comments on commit fec6a97

Please sign in to comment.