Search in sources :

Example 56 with ParsedCommandLine

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

the class PropertyReplacementTestCase method testNodeType.

@Test
public void testNodeType() throws Exception {
    final ParsedCommandLine parsed = parse("/${" + NODE_TYPE_PROP_NAME + "}=test:op");
    final OperationRequestAddress address = parsed.getAddress();
    assertNotNull(address);
    assertEquals(NODE_TYPE_PROP_VALUE, address.getNodeType());
    assertEquals("test", address.getNodeName());
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) OperationRequestAddress(org.jboss.as.cli.operation.OperationRequestAddress) Test(org.junit.Test)

Example 57 with ParsedCommandLine

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

the class PropertyReplacementTestCase method testOperationNameAndValue.

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

Example 58 with ParsedCommandLine

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

the class PropertyReplacementTestCase method testCommandArgumentNameAndValue.

@Test
public void testCommandArgumentNameAndValue() throws Exception {
    final ParsedCommandLine parsed = parse("command-name --${" + OP_PROP_PROP_NAME + "}=${" + OP_PROP_PROP_NAME + "}");
    assertEquals("command-name", parsed.getOperationName());
    // there is a different config option whether to resolve argument values
    assertEquals(parsed.getPropertyValue("--" + OP_PROP_PROP_VALUE), "${" + OP_PROP_PROP_NAME + "}");
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) Test(org.junit.Test)

Example 59 with ParsedCommandLine

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

the class CommandLineArgumentsTestCase method testDefault.

@Test
public void testDefault() throws Exception {
    ParsedCommandLine args = parse("deploy ../../../../testsuite/smoke/target/deployments/test-deployment.sar --name=my.sar --disabled --runtime-name=myrt.sar --force");
    assertTrue(args.hasProperties());
    assertTrue(args.hasProperty("--name"));
    assertTrue(args.hasProperty("--runtime-name"));
    assertTrue(args.hasProperty("--disabled"));
    assertTrue(args.hasProperty("--force"));
    List<String> otherArgs = args.getOtherProperties();
    assertEquals(1, otherArgs.size());
    assertEquals("../../../../testsuite/smoke/target/deployments/test-deployment.sar", otherArgs.get(0));
    assertNull(args.getOutputTarget());
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) Test(org.junit.Test)

Example 60 with ParsedCommandLine

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

the class PatchHandler method createPatchOperationTarget.

private PatchOperationTarget createPatchOperationTarget(CommandContext ctx) throws CommandLineException {
    final PatchOperationTarget target;
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    if (ctx.getModelControllerClient() != null) {
        if (distribution.isPresent(args)) {
            throw new CommandFormatException(distribution.getFullName() + " is not allowed when connected to the controller.");
        }
        if (modulePath.isPresent(args)) {
            throw new CommandFormatException(modulePath.getFullName() + " is not allowed when connected to the controller.");
        }
        if (bundlePath.isPresent(args)) {
            throw new CommandFormatException(bundlePath.getFullName() + " is not allowed when connected to the controller.");
        }
        if (ctx.isDomainMode()) {
            String hostName = host.getValue(args, true);
            target = PatchOperationTarget.createHost(hostName, ctx.getModelControllerClient());
        } else {
            target = PatchOperationTarget.createStandalone(ctx.getModelControllerClient());
        }
    } else {
        final String jbossHome = getJBossHome(args);
        final File root = new File(jbossHome);
        final List<File> modules = getFSArgument(modulePath, args, root, "modules");
        final List<File> bundles = getFSArgument(bundlePath, args, root, "bundles");
        try {
            target = PatchOperationTarget.createLocal(root, modules, bundles);
        } catch (Exception e) {
            throw new CommandLineException("Unable to apply patch to local JBOSS_HOME=" + jbossHome, e);
        }
    }
    return target;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ZipFile(java.util.zip.ZipFile) File(java.io.File) PatchOperationTarget(org.jboss.as.patching.tool.PatchOperationTarget) XMLStreamException(javax.xml.stream.XMLStreamException) ZipException(java.util.zip.ZipException) CommandFormatException(org.jboss.as.cli.CommandFormatException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandLineException(org.jboss.as.cli.CommandLineException)

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