Search in sources :

Example 1 with SubstitutedLine

use of org.jboss.as.cli.parsing.StateParser.SubstitutedLine in project wildfly-core by wildfly.

the class OperationRequestCompleter method completeWithValueCompleter.

private int completeWithValueCompleter(CommandContext ctx, ParsedCommandLine parsedCmd, Collection<CommandArgument> allArgs, String argName, String buffer, List<String> candidates, String chunk, int result, CommandLineCompleter valueCompleter) {
    if (chunk == null) {
        // Complete with false if boolean
        for (CommandArgument arg : allArgs) {
            String argFullName = arg.getFullName();
            if (argFullName.equals(argName)) {
                if (!arg.isValueRequired()) {
                    candidates.add(Util.FALSE);
                    return buffer.length();
                }
            }
        }
    }
    // Call the value completer.
    // Completion is done with substituted line, so returned offset
    // is possibly wrong.
    // Some completers are reseting the CommandContext referenced parsed
    // command. We need to keep a local reference to substitution
    // to compute substitution index after completion occured.
    SubstitutedLine substitutions = parsedCmd.getSubstitutions();
    final String normalizedChunk = chunk == null ? "" : chunk;
    int valueResult = valueCompleter.complete(ctx, normalizedChunk, normalizedChunk.length(), candidates);
    // No proposition.
    if (valueResult < 0) {
        return valueResult;
    } else {
        // or the propertyListEnd if no more properties.
        if (suggestionEqualsUserEntry(candidates, chunk, valueResult)) {
            final CommandLineFormat format = parsedCmd.getFormat();
            if (format != null) {
                for (CommandArgument arg : allArgs) {
                    try {
                        if (arg.canAppearNext(ctx)) {
                            candidates.set(0, "" + 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.
                return buffer.length();
            }
        }
        // WFCORE-3190 ignore trailing spaces after the cursor position
        int trailOffset = substitutions.getSubstitued().substring(result).length() - normalizedChunk.length();
        return result + valueResult + trailOffset;
    }
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandArgument(org.jboss.as.cli.CommandArgument) SubstitutedLine(org.jboss.as.cli.parsing.StateParser.SubstitutedLine) CommandLineFormat(org.jboss.as.cli.CommandLineFormat)

Aggregations

CommandArgument (org.jboss.as.cli.CommandArgument)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandLineFormat (org.jboss.as.cli.CommandLineFormat)1 SubstitutedLine (org.jboss.as.cli.parsing.StateParser.SubstitutedLine)1