From af1d297715aa09224e2d9b81960da1cfebc904ed Mon Sep 17 00:00:00 2001 From: ChristinaDsl Date: Mon, 10 Apr 2023 17:40:57 +0300 Subject: [PATCH] [WFCORE-4916] Unclear attribute name completion for LIST type --- .../cli/impl/AttributeNamePathCompleter.java | 5 ++++ .../operation/OperationRequestCompleter.java | 27 ++++++++++++++----- .../DefaultOperationCandidatesProvider.java | 2 +- .../AttributeNamePathCompletionTestCase.java | 2 +- .../management/cli/CliCompletionTestCase.java | 19 ++++++++++--- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/cli/src/main/java/org/jboss/as/cli/impl/AttributeNamePathCompleter.java b/cli/src/main/java/org/jboss/as/cli/impl/AttributeNamePathCompleter.java index 68ff0897d7d..48d1316b1be 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/AttributeNamePathCompleter.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/AttributeNamePathCompleter.java @@ -332,6 +332,11 @@ public Collection 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(""); } } } diff --git a/cli/src/main/java/org/jboss/as/cli/operation/OperationRequestCompleter.java b/cli/src/main/java/org/jboss/as/cli/operation/OperationRequestCompleter.java index 3662f515299..942a7de421c 100644 --- a/cli/src/main/java/org/jboss/as/cli/operation/OperationRequestCompleter.java +++ b/cli/src/main/java/org/jboss/as/cli/operation/OperationRequestCompleter.java @@ -23,7 +23,6 @@ import org.jboss.as.cli.parsing.StateParser.SubstitutedLine; import org.jboss.logging.Logger; - /** * * @author Alexey Loubyansky @@ -401,13 +400,13 @@ 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) { @@ -415,8 +414,10 @@ private int completeWithValueCompleter(CommandContext ctx, ParsedCommandLine par } } // 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(); } } @@ -717,12 +718,26 @@ private boolean suggestionEqualsUserEntry(List 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 candidates){ + if(candidates.contains("[") || candidates.contains(".")){ + return true; + }else if(candidates.contains("")){ + candidates.remove(""); + return true; } + return false; } protected CommandLineCompleter getValueCompleter(CommandContext ctx, Iterable allArgs, final String argName) { diff --git a/cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationCandidatesProvider.java b/cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationCandidatesProvider.java index eaf9e8db19f..bc78196b8b7 100644 --- a/cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationCandidatesProvider.java +++ b/cli/src/main/java/org/jboss/as/cli/operation/impl/DefaultOperationCandidatesProvider.java @@ -427,7 +427,7 @@ protected List getPropertiesFromPropList(List 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; diff --git a/cli/src/test/java/org/jboss/as/cli/parsing/test/AttributeNamePathCompletionTestCase.java b/cli/src/test/java/org/jboss/as/cli/parsing/test/AttributeNamePathCompletionTestCase.java index 37e49f7071f..3e6795d00e9 100644 --- a/cli/src/test/java/org/jboss/as/cli/parsing/test/AttributeNamePathCompletionTestCase.java +++ b/cli/src/test/java/org/jboss/as/cli/parsing/test/AttributeNamePathCompletionTestCase.java @@ -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(); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/CliCompletionTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/CliCompletionTestCase.java index 5cb989d60ab..a7effa9cd1a 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/CliCompletionTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/management/cli/CliCompletionTestCase.java @@ -1140,10 +1140,12 @@ public void testCommandsCompletion2() throws Exception { List 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")); } @@ -1157,6 +1159,17 @@ public void testCommandsCompletion2() throws Exception { assertTrue(candidates.toString(), candidates.isEmpty()); } + { + String cmd = "read-attribute management-minor-version"; + List 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 candidates = new ArrayList<>();