Search in sources :

Example 26 with ParsedCommandLine

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

the class VariablesTestCase method testOperationNameAndValue.

@Test
public void testOperationNameAndValue() throws Exception {
    final ParsedCommandLine parsed = parse(":write-attribute($" + OP_PROP_VAR_NAME + "=$" + OP_PROP_VAR_NAME + ")");
    assertEquals("write-attribute", parsed.getOperationName());
    // variables unlike system properties are always resolved
    assertEquals(OP_PROP_VAR_VALUE, parsed.getPropertyValue(OP_PROP_VAR_VALUE));
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) Test(org.junit.Test)

Example 27 with ParsedCommandLine

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

the class ReadAttributeHandler method buildRequestWithoutHeaders.

/* (non-Javadoc)
     * @see org.jboss.as.cli.OperationCommand#buildRequest(org.jboss.as.cli.CommandContext)
     */
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    final String name = this.name.getValue(parsedCmd);
    if (name == null || name.isEmpty()) {
        throw new CommandFormatException("Required argument " + this.name.getFullName() + " is not specified.");
    }
    final OperationRequestAddress address = getAddress(ctx, false);
    ModelNode req = Util.buildRequest(ctx, address, Util.READ_ATTRIBUTE);
    req.get(Util.NAME).set(name);
    if (resolve.isPresent(parsedCmd)) {
        req.get(Util.RESOLVE_EXPRESSIONS).set(true);
    }
    final String includeDefaults = this.includeDefaults.getValue(parsedCmd);
    if (includeDefaults != null && !includeDefaults.isEmpty()) {
        req.get(Util.INCLUDE_DEFAULTS).set(includeDefaults);
    }
    if (verbose.isPresent(parsedCmd)) {
        final ModelNode composite = new ModelNode();
        composite.get(Util.OPERATION).set(Util.COMPOSITE);
        composite.get(Util.ADDRESS).setEmptyList();
        final ModelNode steps = composite.get(Util.STEPS);
        steps.add(req);
        steps.add(Util.buildRequest(ctx, address, Util.READ_RESOURCE_DESCRIPTION));
        req = composite;
    }
    return req;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ModelNode(org.jboss.dmr.ModelNode) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 28 with ParsedCommandLine

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

the class ReadAttributeHandler method getAddress.

protected OperationRequestAddress getAddress(CommandContext ctx, boolean completion) throws CommandFormatException {
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final OperationRequestAddress address;
    if (node.isPresent(args)) {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
        CommandLineParser.CallbackHandler handler = new DefaultCallbackHandler(address);
        // this is for correct parsing of escaped characters
        String nodePath = args.getSubstitutedLine();
        int nodeArgInd = nodePath.indexOf(" --node=");
        if (nodeArgInd < 0) {
            if (completion) {
                // Under completion.
                nodeArgInd = nodePath.indexOf(" --node");
                if (nodeArgInd >= 0) {
                    return new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
                }
            }
            throw new CommandFormatException("Couldn't locate ' --node=' in the line: '" + nodePath + "'");
        }
        int nodeArgEndInd = nodeArgInd + 8;
        do {
            nodeArgEndInd = nodePath.indexOf(' ', nodeArgEndInd);
            if (nodeArgEndInd < 0) {
                nodeArgEndInd = nodePath.length();
            } else if (nodePath.charAt(nodeArgEndInd - 1) == '\\') {
                ++nodeArgEndInd;
            } else {
                break;
            }
        } while (nodeArgEndInd < nodePath.length());
        nodePath = nodePath.substring(nodeArgInd + 8, nodeArgEndInd);
        ctx.getCommandLineParser().parse(nodePath, handler);
    } else {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
    }
    return address;
}
Also used : DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) CommandLineParser(org.jboss.as.cli.operation.CommandLineParser) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 29 with ParsedCommandLine

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

the class ReadOperationHandler method buildRequestWithoutHeaders.

/* (non-Javadoc)
     * @see org.jboss.as.cli.OperationCommand#buildRequest(org.jboss.as.cli.CommandContext)
     */
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    final String name = this.name.getValue(parsedCmd);
    if (name == null || name.isEmpty()) {
        final OperationRequestAddress address = getAddress(ctx);
        final ModelNode request = Util.buildRequest(ctx, address, Util.READ_OPERATION_NAMES);
        if (ctx.getConfig().isAccessControl()) {
            request.get(Util.ACCESS_CONTROL).set(true);
        }
        return request;
    }
    final OperationRequestAddress address = getAddress(ctx);
    ModelNode req = Util.buildRequest(ctx, address, Util.READ_OPERATION_DESCRIPTION);
    req.get(Util.NAME).set(name);
    return req;
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ModelNode(org.jboss.dmr.ModelNode) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

Example 30 with ParsedCommandLine

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

the class ReadOperationHandler method getAddress.

protected OperationRequestAddress getAddress(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final OperationRequestAddress address;
    if (node.isPresent(args)) {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
        CommandLineParser.CallbackHandler handler = new DefaultCallbackHandler(address);
        // this is for correct parsing of escaped characters
        String nodePath = args.getOriginalLine();
        int nodeArgInd = nodePath.indexOf(" --node=");
        if (nodeArgInd < 0) {
            throw new CommandFormatException("Couldn't locate ' --node=' in the line: '" + nodePath + "'");
        }
        int nodeArgEndInd = nodeArgInd + 8;
        do {
            nodeArgEndInd = nodePath.indexOf(' ', nodeArgEndInd);
            if (nodeArgEndInd < 0) {
                nodeArgEndInd = nodePath.length();
            } else if (nodePath.charAt(nodeArgEndInd - 1) == '\\') {
                ++nodeArgEndInd;
            } else {
                break;
            }
        } while (nodeArgEndInd < nodePath.length());
        nodePath = nodePath.substring(nodeArgInd + 8, nodeArgEndInd);
        ctx.getCommandLineParser().parse(nodePath, handler);
    } else {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
    }
    return address;
}
Also used : DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) CommandLineParser(org.jboss.as.cli.operation.CommandLineParser) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress)

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