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());
}
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);
}
}
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;
}
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());
}
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"));
}
Aggregations