Search in sources :

Example 1 with ArgumentWithoutValue

use of org.jboss.as.cli.impl.ArgumentWithoutValue in project wildfly-core by wildfly.

the class EmbedHostControllerHandler method create.

static EmbedHostControllerHandler create(final AtomicReference<EmbeddedProcessLaunch> hostControllerReference, final CommandContext ctx, final boolean modular) {
    EmbedHostControllerHandler result = new EmbedHostControllerHandler(hostControllerReference);
    final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
    if (!modular) {
        result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
    }
    result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
    result.domainConfig = new ArgumentWithValue(result, DOMAIN_CONFIG);
    result.hostConfig = new ArgumentWithValue(result, HOST_CONFIG);
    result.dashC = new ArgumentWithValue(result, "-c");
    result.dashC.addCantAppearAfter(result.domainConfig);
    result.domainConfig.addCantAppearAfter(result.dashC);
    result.timeout = new ArgumentWithValue(result, "--timeout");
    result.emptyDomainConfig = new ArgumentWithoutValue(result, EMPTY_DOMAIN_CONFIG);
    result.removeExistingDomainConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_DOMAIN_CONFIG);
    result.emptyHostConfig = new ArgumentWithoutValue(result, EMPTY_HOST_CONFIG);
    result.removeExistingHostConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_HOST_CONFIG);
    return result;
}
Also used : SimpleTabCompleter(org.jboss.as.cli.handlers.SimpleTabCompleter) FileSystemPathArgument(org.jboss.as.cli.impl.FileSystemPathArgument) ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) FilenameTabCompleter(org.jboss.as.cli.handlers.FilenameTabCompleter) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue)

Example 2 with ArgumentWithoutValue

use of org.jboss.as.cli.impl.ArgumentWithoutValue in project wildfly-core by wildfly.

the class OperationRequestCompleter method completeArgumentValueAndPropertyNames.

private int completeArgumentValueAndPropertyNames(CommandContext ctx, ParsedCommandLine parsedCmd, Collection<CommandArgument> allArgs, List<String> candidates, String chunk, int result) {
    // lastArg will be not null if its name is equals to the last typed one.
    CommandArgument lastArg = null;
    // All property present means proposing end of list instead of property
    // separator when the last property is a boolean one.
    boolean allPropertiesPresent = true;
    // e.g.: recursive and recursive-depth
    for (CommandArgument arg : allArgs) {
        try {
            if (arg.canAppearNext(ctx)) {
                allPropertiesPresent = false;
            } else if (arg.getFullName().equals(chunk)) {
                lastArg = arg;
            }
        } catch (CommandFormatException e) {
            return -1;
        }
    }
    boolean needNeg = false;
    // We must first check that we have no matches for option names
    // prior to call the argument (option with no value) value completers
    // Otherwise we can enter the case where value completer would complete
    // an option name. That is possible because value completer parsers are not strict.
    // for example: ls --hel<TAB> ==> --hel will be completed by the node-path completer
    // and this can give strange completion result.
    boolean optionMatch = false;
    for (CommandArgument arg : allArgs) {
        try {
            if (arg.canAppearNext(ctx)) {
                if (arg.getIndex() < 0) {
                    String argFullName = arg.getFullName();
                    if (chunk != null && argFullName.startsWith(chunk)) {
                        if (!parsedCmd.isLastPropertyNegated()) {
                            optionMatch = true;
                            break;
                        } else // We can only add candidates that are of type boolean
                        if (!arg.isValueRequired()) {
                            optionMatch = true;
                            break;
                        }
                    }
                }
            }
        } catch (CommandFormatException e) {
            return -1;
        }
    }
    for (CommandArgument arg : allArgs) {
        try {
            if (arg.canAppearNext(ctx)) {
                if (arg.getIndex() >= 0) {
                    if (optionMatch) {
                        continue;
                    }
                    CommandLineCompleter valCompl = arg.getValueCompleter();
                    if (valCompl != null) {
                        final String value = chunk == null ? "" : chunk;
                        valCompl.complete(ctx, value, value.length(), 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 {
                    String argFullName = arg.getFullName();
                    if (chunk == null || argFullName.startsWith(chunk)) {
                        /* The following complexity is due to cases like:
                                 recursive and recursive-depth. Both start with the same name
                                 but are of different types. Completion can't propose
                                 recursive-depth of !recursive has been typed.
                                 If the last property is not negated,
                                 we can add all properties with the same name.
                             */
                        if (!parsedCmd.isLastPropertyNegated()) {
                            candidates.add(arg.getDecoratedName());
                        } else // We can only add candidates that are of type boolean
                        {
                            if (!arg.isValueRequired()) {
                                candidates.add(arg.getDecoratedName());
                            }
                        }
                    }
                    // and this property is not already negated.
                    if (!arg.isValueRequired() && !parsedCmd.isLastPropertyNegated()) {
                        needNeg = true;
                    }
                }
            }
        } catch (CommandFormatException e) {
            return -1;
        }
    }
    // Propose not operator only after a property separator
    if (needNeg && parsedCmd.endsOnPropertySeparator()) {
        candidates.add(Util.NOT_OPERATOR);
    }
    if (lastArg != null) {
        if (lastArg.isValueRequired()) {
            candidates.add(lastArg.getFullName() + "=");
        } else if (lastArg instanceof ArgumentWithoutValue) {
            ArgumentWithoutValue argWithoutValue = (ArgumentWithoutValue) lastArg;
            // If the last argument is exclusive, no need to add any separator
            if (!argWithoutValue.isExclusive()) {
                // to make completion propose next argument
                if (!allPropertiesPresent) {
                    CommandLineFormat format = parsedCmd.getFormat();
                    if (format != null && format.getPropertySeparator() != null) {
                        candidates.add(lastArg.getFullName() + format.getPropertySeparator());
                    }
                }
            }
        } else {
            // We are completing implicit values for operation.
            CommandLineFormat format = parsedCmd.getFormat();
            // enough.
            if (!parsedCmd.isLastPropertyNegated()) {
                candidates.add("=" + Util.FALSE);
                result = recalculateResult(parsedCmd, candidates, chunk, result);
            }
            if (format != null && format.getPropertyListEnd() != null && format.getPropertyListEnd().length() > 0) {
                candidates.add(format.getPropertyListEnd());
                result = recalculateResult(parsedCmd, candidates, chunk, result);
                if (!allPropertiesPresent) {
                    candidates.add(format.getPropertySeparator());
                    result = recalculateResult(parsedCmd, candidates, chunk, result);
                }
            }
        }
    }
    if (candidates.isEmpty()) {
        if (chunk == null && !parsedCmd.endsOnSeparator()) {
            final CommandLineFormat format = parsedCmd.getFormat();
            if (format != null && format.getPropertyListEnd() != null && format.getPropertyListEnd().length() > 0) {
                candidates.add(format.getPropertyListEnd());
                result = recalculateResult(parsedCmd, candidates, chunk, result);
            }
        }
    } else {
        Collections.sort(candidates);
    }
    return result;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandArgument(org.jboss.as.cli.CommandArgument) CommandLineCompleter(org.jboss.as.cli.CommandLineCompleter) CommandLineFormat(org.jboss.as.cli.CommandLineFormat) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue)

Example 3 with ArgumentWithoutValue

use of org.jboss.as.cli.impl.ArgumentWithoutValue in project wildfly-core by wildfly.

the class LsHandler method getDynamicOptions.

private Map<String, CommandArgument> getDynamicOptions(CommandContext ctx) throws CommandFormatException {
    if (ctx.getModelControllerClient() == null) {
        return Collections.emptyMap();
    }
    final OperationRequestAddress address = getOperationRequestAddress(ctx);
    if (address.endsOnType()) {
        return Collections.emptyMap();
    }
    final ModelNode req = new ModelNode();
    if (address.isEmpty()) {
        req.get(Util.ADDRESS).setEmptyList();
    } else {
        final ModelNode addrNode = req.get(Util.ADDRESS);
        for (OperationRequestAddress.Node node : address) {
            addrNode.add(node.getType(), node.getName());
        }
    }
    req.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
    Map<String, CommandArgument> options = Collections.emptyMap();
    try {
        final ModelNode response = ctx.getModelControllerClient().execute(req);
        if (Util.isSuccess(response)) {
            if (response.hasDefined(Util.RESULT)) {
                final ModelNode result = response.get(Util.RESULT);
                if (result.hasDefined(Util.ATTRIBUTES)) {
                    options = new TreeMap<>();
                    ModelNode attributes = result.get(Util.ATTRIBUTES);
                    for (String key : attributes.keys()) {
                        ModelNode attribute = attributes.get(key);
                        for (String k : attribute.keys()) {
                            ArgumentWithoutValue wv = new ArgumentWithoutValue(new CommandHandlerWithArguments() {

                                @Override
                                public boolean isAvailable(CommandContext ctx) {
                                    return LsHandler.this.isAvailable(ctx);
                                }

                                @Override
                                public boolean isBatchMode(CommandContext ctx) {
                                    return LsHandler.this.isBatchMode(ctx);
                                }

                                @Override
                                public void handle(CommandContext ctx) throws CommandLineException {
                                    LsHandler.this.handle(ctx);
                                }

                                @Override
                                public void addArgument(CommandArgument arg) {
                                // Noop.
                                }
                            }, "--" + k);
                            wv.addRequiredPreceding(l);
                            options.put("--" + k, wv);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return options;
}
Also used : Node(org.jboss.as.cli.operation.OperationRequestAddress.Node) CommandContext(org.jboss.as.cli.CommandContext) CommandArgument(org.jboss.as.cli.CommandArgument) CommandLineException(org.jboss.as.cli.CommandLineException) OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandFormatException(org.jboss.as.cli.CommandFormatException) ModelNode(org.jboss.dmr.ModelNode) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 4 with ArgumentWithoutValue

use of org.jboss.as.cli.impl.ArgumentWithoutValue in project wildfly-core by wildfly.

the class EmbedServerHandler method create.

static EmbedServerHandler create(final AtomicReference<EmbeddedProcessLaunch> serverReference, CommandContext ctx, boolean modular) {
    EmbedServerHandler result = new EmbedServerHandler(serverReference);
    final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
    if (!modular) {
        result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
    }
    result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
    result.serverConfig = new ArgumentWithValue(result, "--server-config");
    result.dashC = new ArgumentWithValue(result, "-c");
    result.dashC.addCantAppearAfter(result.serverConfig);
    result.serverConfig.addCantAppearAfter(result.dashC);
    result.adminOnly = new ArgumentWithValue(result, SimpleTabCompleter.BOOLEAN, "--admin-only");
    result.emptyConfig = new ArgumentWithoutValue(result, "--empty-config");
    result.removeExisting = new ArgumentWithoutValue(result, "--remove-existing");
    result.removeExisting.addRequiredPreceding(result.emptyConfig);
    result.timeout = new ArgumentWithValue(result, "--timeout");
    return result;
}
Also used : SimpleTabCompleter(org.jboss.as.cli.handlers.SimpleTabCompleter) FileSystemPathArgument(org.jboss.as.cli.impl.FileSystemPathArgument) ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) FilenameTabCompleter(org.jboss.as.cli.handlers.FilenameTabCompleter) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue)

Aggregations

ArgumentWithoutValue (org.jboss.as.cli.impl.ArgumentWithoutValue)4 CommandArgument (org.jboss.as.cli.CommandArgument)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 FilenameTabCompleter (org.jboss.as.cli.handlers.FilenameTabCompleter)2 SimpleTabCompleter (org.jboss.as.cli.handlers.SimpleTabCompleter)2 ArgumentWithValue (org.jboss.as.cli.impl.ArgumentWithValue)2 FileSystemPathArgument (org.jboss.as.cli.impl.FileSystemPathArgument)2 IOException (java.io.IOException)1 CommandContext (org.jboss.as.cli.CommandContext)1 CommandLineCompleter (org.jboss.as.cli.CommandLineCompleter)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 CommandLineFormat (org.jboss.as.cli.CommandLineFormat)1 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)1 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)1 Node (org.jboss.as.cli.operation.OperationRequestAddress.Node)1 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)1 ModelNode (org.jboss.dmr.ModelNode)1