Search in sources :

Example 76 with ParsedCommandLine

use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.

the class ReadAttributeHandler method recognizeArguments.

@Override
protected void recognizeArguments(CommandContext ctx) throws CommandFormatException {
    super.recognizeArguments(ctx);
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    if (resolve.isPresent(parsedCmd)) {
        ModelNode op = new ModelNode();
        op.get("operation").set("read-operation-description");
        op.get("name").set("read-attribute");
        OperationRequestAddress address = getAddress(ctx, false);
        if (address.isEmpty()) {
            op.get(Util.ADDRESS).setEmptyList();
        } else {
            final ModelNode addrNode = op.get(Util.ADDRESS);
            for (OperationRequestAddress.Node node : address) {
                addrNode.add(node.getType(), node.getName());
            }
        }
        ModelNode returnVal = new ModelNode();
        try {
            if (ctx.getModelControllerClient() != null) {
                returnVal = ctx.getModelControllerClient().execute(op);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (returnVal.hasDefined("outcome") && returnVal.get("outcome").asString().equals("success")) {
            ModelNode result = returnVal.get("result");
            if (result.hasDefined("request-properties")) {
                ModelNode properties = result.get("request-properties");
                if (!properties.hasDefined("resolve-expressions")) {
                    throw new OperationFormatException("Resolve Expression argument not available at this location.");
                }
            }
        }
    }
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 77 with ParsedCommandLine

use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.

the class ReloadHandler method isAdminOnly.

private boolean isAdminOnly(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    boolean legacy = this.adminOnly.isPresent(args) && "TRUE".equalsIgnoreCase(this.adminOnly.getValue(args));
    boolean mode = this.startMode.isPresent(args) && ADMIN_ONLY.equalsIgnoreCase(this.startMode.getValue(args));
    return mode || legacy;
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 78 with ParsedCommandLine

use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.

the class ReloadHandler method buildRequestWithoutHeaders.

@Override
protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final ModelNode op = new ModelNode();
    if (ctx.isDomainMode()) {
        if (useCurrentServerConfig.isPresent(args)) {
            throw new CommandFormatException(useCurrentServerConfig.getFullName() + " is not allowed in the domain mode.");
        }
        if (serverConfig.isPresent(args)) {
            throw new CommandFormatException(serverConfig.getFullName() + " is not allowed in the domain mode.");
        }
        final String hostName = host.getValue(args);
        if (hostName == null) {
            throw new CommandFormatException("Missing required argument " + host.getFullName());
        }
        op.get(Util.ADDRESS).add(Util.HOST, hostName);
        setBooleanArgument(args, op, restartServers, "restart-servers");
        setBooleanArgument(args, op, this.useCurrentDomainConfig, "use-current-domain-config");
        setBooleanArgument(args, op, this.useCurrentHostConfig, "use-current-host-config");
        setStringValue(args, op, hostConfig, "host-config");
        setStringValue(args, op, domainConfig, "domain-config");
    } else {
        if (host.isPresent(args)) {
            throw new CommandFormatException(host.getFullName() + " is not allowed in the standalone mode.");
        }
        if (useCurrentDomainConfig.isPresent(args)) {
            throw new CommandFormatException(useCurrentDomainConfig.getFullName() + " is not allowed in the standalone mode.");
        }
        if (useCurrentHostConfig.isPresent(args)) {
            throw new CommandFormatException(useCurrentHostConfig.getFullName() + " is not allowed in the standalone mode.");
        }
        if (restartServers.isPresent(args)) {
            throw new CommandFormatException(restartServers.getFullName() + " is not allowed in the standalone mode.");
        }
        if (hostConfig.isPresent(args)) {
            throw new CommandFormatException(hostConfig.getFullName() + " is not allowed in the standalone mode.");
        }
        if (domainConfig.isPresent(args)) {
            throw new CommandFormatException(domainConfig.getFullName() + " is not allowed in the standalone mode.");
        }
        op.get(Util.ADDRESS).setEmptyList();
        setBooleanArgument(args, op, this.useCurrentServerConfig, "use-current-server-config");
        setStringValue(args, op, serverConfig, "server-config");
    }
    op.get(Util.OPERATION).set(Util.RELOAD);
    setStartMode(ctx, args, op);
    return op;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ModelNode(org.jboss.dmr.ModelNode)

Example 79 with ParsedCommandLine

use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.

the class ForHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    if (ForControlFlow.get(ctx) != null) {
        throw new CommandFormatException("for is not allowed while in for block");
    }
    final BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
        throw new CommandFormatException("for is not allowed while in batch mode.");
    }
    String argsStr = ctx.getArgumentsString();
    if (argsStr == null) {
        throw new CommandFormatException("The command is missing arguments.");
    }
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final String varName = this.varName.getOriginalValue(args, true);
    int i = argsStr.indexOf(varName);
    if (i < 0) {
        throw new CommandFormatException("Failed to locate '" + varName + "' in '" + argsStr + "'");
    }
    i = argsStr.indexOf("in", i + varName.length());
    if (i < 0) {
        throw new CommandFormatException("Failed to locate 'in' in '" + argsStr + "'");
    }
    final String requestStr = argsStr.substring(i + 2);
    ctx.registerRedirection(new ForControlFlow(ctx, varName, requestStr));
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) BatchManager(org.jboss.as.cli.batch.BatchManager)

Example 80 with ParsedCommandLine

use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.

the class ArgumentWithoutValue method canAppearNext.

@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
    if (!access.isSatisfied(ctx)) {
        return false;
    }
    ParsedCommandLine args = ctx.getParsedCommandLine();
    if (exclusive) {
        final Set<String> propertyNames = args.getPropertyNames();
        if (propertyNames.isEmpty()) {
            final List<String> values = args.getOtherProperties();
            if (values.isEmpty()) {
                return true;
            }
            if (index == -1) {
                return false;
            }
            return !(index == 0 && values.size() == 1);
        }
        if (propertyNames.size() != 1) {
            return false;
        }
        if (args.getLastParsedPropertyName() == null) {
            return false;
        }
        final List<String> values = args.getOtherProperties();
        if (!values.isEmpty()) {
            return false;
        }
        // The argument is already there, don't add it.
        if (fullName.equals(args.getLastParsedPropertyName())) {
            return false;
        }
        return fullName.startsWith(args.getLastParsedPropertyName()) || (shortName != null && shortName.startsWith(args.getLastParsedPropertyName()));
    }
    if (isPresent(args)) {
        // An argument without value has no value
        return false;
    }
    for (CommandArgument arg : cantAppearAfter) {
        if (arg.isPresent(args)) {
            return false;
        }
    }
    if (requiredPreceding != null) {
        for (CommandArgument arg : requiredPreceding) {
            if (arg.isPresent(args)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : CommandArgument(org.jboss.as.cli.CommandArgument) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Aggregations

ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)95 Test (org.junit.Test)42 CommandFormatException (org.jboss.as.cli.CommandFormatException)38 ModelNode (org.jboss.dmr.ModelNode)26 CommandLineException (org.jboss.as.cli.CommandLineException)14 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)14 File (java.io.File)12 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)8 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)8 CommandArgument (org.jboss.as.cli.CommandArgument)4 CommandContext (org.jboss.as.cli.CommandContext)4 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)4 ZipException (java.util.zip.ZipException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 CommandException (org.aesh.command.CommandException)3 BatchManager (org.jboss.as.cli.batch.BatchManager)3 CommandLineParser (org.jboss.as.cli.operation.CommandLineParser)3 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)3