Search in sources :

Example 11 with CommandLineCompleter

use of org.jboss.as.cli.CommandLineCompleter 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;
    }
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandArgument(org.jboss.as.cli.CommandArgument) CommandLineCompleter(org.jboss.as.cli.CommandLineCompleter)

Aggregations

CommandLineCompleter (org.jboss.as.cli.CommandLineCompleter)11 CommandArgument (org.jboss.as.cli.CommandArgument)6 CommandFormatException (org.jboss.as.cli.CommandFormatException)4 Property (org.jboss.dmr.Property)4 ArrayList (java.util.ArrayList)3 CommandContext (org.jboss.as.cli.CommandContext)3 ModelNode (org.jboss.dmr.ModelNode)3 ArgumentValueConverter (org.jboss.as.cli.ArgumentValueConverter)2 ArgumentWithValue (org.jboss.as.cli.impl.ArgumentWithValue)2 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)2 ModelType (org.jboss.dmr.ModelType)2 List (java.util.List)1 CommandLineFormat (org.jboss.as.cli.CommandLineFormat)1 OperationCommand (org.jboss.as.cli.OperationCommand)1 MockCommandContext (org.jboss.as.cli.completion.mock.MockCommandContext)1 SimpleTabCompleter (org.jboss.as.cli.handlers.SimpleTabCompleter)1 ArgumentWithoutValue (org.jboss.as.cli.impl.ArgumentWithoutValue)1 Test (org.junit.Test)1