Search in sources :

Example 46 with ParsedCommandLine

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

the class ForControlFlow method handle.

@Override
public void handle(CommandContext ctx) throws CommandLineException {
    final ParsedCommandLine line = ctx.getParsedCommandLine();
    if (line.getFormat() == CommandFormat.INSTANCE) {
        // let the help through
        final String cmd = line.getOperationName();
        if ("for".equals(cmd)) {
            throw new CommandFormatException("for is not allowed while in for block");
        }
        if (line.hasProperty("--help") || line.hasProperty("-h") || "done".equals(cmd) || "help".equals(cmd)) {
            registration.handle(line);
            return;
        }
    }
    forBlock.add(line.getOriginalLine());
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 47 with ParsedCommandLine

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

the class ASModuleHandler method doHandle.

@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
    final String actionValue = action.getValue(parsedCmd);
    if (actionValue == null) {
        throw new CommandFormatException("Action argument is missing: " + ACTION_ADD + " or " + ACTION_REMOVE);
    }
    if (ACTION_ADD.equals(actionValue)) {
        addModule(ctx, parsedCmd);
    } else if (ACTION_REMOVE.equals(actionValue)) {
        removeModule(parsedCmd, ctx);
    } else {
        throw new CommandFormatException("Unexpected action '" + actionValue + "', expected values: " + ACTION_ADD + ", " + ACTION_REMOVE);
    }
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 48 with ParsedCommandLine

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

the class MockOperationCandidatesProvider method getProperties.

@Override
public List<CommandArgument> getProperties(CommandContext ctx, String operationName, OperationRequestAddress address) {
    MockOperation operation = root.getOperation(operationName);
    if (operation == null) {
        return Collections.emptyList();
    }
    final List<MockOperationProperty> properties = operation.getProperties();
    final List<CommandArgument> result = new ArrayList<CommandArgument>(properties.size());
    for (final MockOperationProperty property : properties) {
        String name = property.getName();
        result.add(new CommandArgument() {

            @Override
            public String getFullName() {
                return name;
            }

            @Override
            public String getShortName() {
                return null;
            }

            @Override
            public int getIndex() {
                return -1;
            }

            @Override
            public boolean isPresent(ParsedCommandLine args) throws CommandFormatException {
                return args.hasProperty(name);
            }

            @Override
            public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
                ParsedCommandLine args = ctx.getParsedCommandLine();
                if (isPresent(args)) {
                    return !isValueComplete(args);
                }
                return true;
            }

            @Override
            public String getValue(ParsedCommandLine args) throws CommandFormatException {
                return args.getPropertyValue(name);
            }

            @Override
            public String getValue(ParsedCommandLine args, boolean required) throws CommandFormatException {
                if (!isPresent(args)) {
                    throw new CommandFormatException("Property '" + name + "' is missing required value.");
                }
                return args.getPropertyValue(name);
            }

            @Override
            public boolean isValueComplete(ParsedCommandLine args) throws CommandFormatException {
                if (!isPresent(args)) {
                    return false;
                }
                if (name.equals(args.getLastParsedPropertyName()) && !args.isLastPropertyNegated()) {
                    return false;
                }
                return true;
            }

            @Override
            public boolean isValueRequired() {
                return property.isValueRequired();
            }

            @Override
            public CommandLineCompleter getValueCompleter() {
                return property.getPossibleValues() != null ? new SimpleTabCompleter(property.getPossibleValues()) : null;
            }
        });
    }
    return result;
}
Also used : SimpleTabCompleter(org.jboss.as.cli.handlers.SimpleTabCompleter) CommandContext(org.jboss.as.cli.CommandContext) CommandArgument(org.jboss.as.cli.CommandArgument) ArrayList(java.util.ArrayList) CommandLineCompleter(org.jboss.as.cli.CommandLineCompleter) CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 49 with ParsedCommandLine

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

the class PropertyReplacementTestCase method testRecursiveReplacement.

@Test
public void testRecursiveReplacement() throws Exception {
    final ParsedCommandLine parsed = parse("${" + PROP_RECURSIVE_NAME + "}");
    assertEquals(OP_PROP_VALUE, parsed.getOperationName());
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) Test(org.junit.Test)

Example 50 with ParsedCommandLine

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

the class PropertyReplacementTestCase method testListParameterValue.

@Test
public void testListParameterValue() throws Exception {
    final ParsedCommandLine parsed = parse(":op(name=[${" + OP_PROP_PROP_NAME + "}])");
    assertEquals("op", parsed.getOperationName());
    assertEquals("[${" + OP_PROP_PROP_NAME + "}]", parsed.getPropertyValue("name"));
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) Test(org.junit.Test)

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