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