Search in sources :

Example 41 with ParsedCommandLine

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

the class DeploymentOverlayHandler method listContent.

protected void listContent(CommandContext ctx) throws CommandLineException {
    final ModelControllerClient client = ctx.getModelControllerClient();
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    assertNotPresent(serverGroups, args);
    assertNotPresent(allServerGroups, args);
    assertNotPresent(allRelevantServerGroups, args);
    assertNotPresent(deployments, args);
    assertNotPresent(content, args);
    assertNotPresent(redeployAffected, args);
    final String name = getName(ctx, true);
    final List<String> content = loadContentFor(client, name);
    if (l.isPresent(args)) {
        for (String contentPath : content) {
            ctx.printLine(contentPath);
        }
    } else {
        ctx.printColumns(content);
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 42 with ParsedCommandLine

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

the class LsHandler method buildRequestWithoutHeaders.

@Override
protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    final OperationRequestAddress address = getOperationRequestAddress(ctx);
    if (address.endsOnType()) {
        final String type = address.getNodeType();
        address.toParentNode();
        final DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(address);
        try {
            builder.setOperationName(Util.READ_CHILDREN_NAMES);
            builder.addProperty(Util.CHILD_TYPE, type);
            return builder.buildRequest();
        } catch (OperationFormatException e) {
            throw new IllegalStateException("Failed to build operation", e);
        }
    }
    final ModelNode composite = new ModelNode();
    composite.get(Util.OPERATION).set(Util.COMPOSITE);
    composite.get(Util.ADDRESS).setEmptyList();
    final ModelNode steps = composite.get(Util.STEPS);
    {
        ModelNode typesRequest = new ModelNode();
        typesRequest.get(Util.OPERATION).set(Util.READ_CHILDREN_TYPES);
        typesRequest = getAddressNode(ctx, address, typesRequest);
        steps.add(typesRequest);
    }
    {
        ModelNode resourceRequest = new ModelNode();
        resourceRequest.get(Util.OPERATION).set(Util.READ_RESOURCE);
        resourceRequest = getAddressNode(ctx, address, resourceRequest);
        resourceRequest.get(Util.INCLUDE_RUNTIME).set(Util.TRUE);
        if (resolve.isPresent(parsedCmd)) {
            resourceRequest.get(Util.RESOLVE_EXPRESSIONS).set(Util.TRUE);
        }
        steps.add(resourceRequest);
    }
    if (l.isPresent(parsedCmd)) {
        steps.add(Util.buildRequest(ctx, address, Util.READ_RESOURCE_DESCRIPTION));
    }
    return composite;
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder) 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 43 with ParsedCommandLine

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

the class LsHandler method getOperationRequestAddress.

private OperationRequestAddress getOperationRequestAddress(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    String nodePathString = nodePath.getValue(parsedCmd);
    final OperationRequestAddress address;
    if (nodePathString != null) {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
        // this is for correct parsing of escaped characters
        // this method could return null
        nodePathString = ctx.getArgumentsString();
        // but this method is useful to handle command lines with line breaks
        if (nodePathString == null) {
            nodePathString = parsedCmd.getOriginalLine();
            int cmdNameLength = parsedCmd.getOperationName().length();
            if (nodePathString.length() == cmdNameLength) {
                return address;
            } else {
                nodePathString = nodePathString.substring(cmdNameLength + 1);
            }
        }
        nodePathString = getNodePath(nodePathString);
        final CommandLineParser.CallbackHandler handler = new DefaultCallbackHandler(address);
        ctx.getCommandLineParser().parse(nodePathString, handler);
    } else {
        address = new DefaultOperationRequestAddress(ctx.getCurrentNodePath());
    }
    return address;
}
Also used : DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress) 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 44 with ParsedCommandLine

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

the class SetVariableHandler method recognizeArguments.

@Override
protected void recognizeArguments(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final Set<String> propertyNames = args.getPropertyNames();
    if (!propertyNames.isEmpty()) {
        final Collection<String> names;
        if (helpArg.isPresent(args)) {
            if (propertyNames.size() == 1) {
                return;
            }
            names = new ArrayList<String>(propertyNames);
            names.remove(helpArg.getFullName());
            names.remove(helpArg.getShortName());
        } else {
            names = propertyNames;
        }
        throw new CommandFormatException("Unrecognized argument names: " + names);
    }
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 45 with ParsedCommandLine

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

the class ArgumentWithValue method toModelNode.

public ModelNode toModelNode(CommandContext ctx) throws CommandFormatException {
    final ParsedCommandLine parsedLine = ctx.getParsedCommandLine();
    final String value = getOriginalValue(parsedLine, false);
    if (value == null) {
        return null;
    }
    return valueConverter.fromString(ctx, value);
}
Also used : 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