return composite;
}
protected ModelNode buildOperationRequest(CommandContext ctx, final String operation) throws CommandFormatException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
if(dependsOnProfile && ctx.isDomainMode()) {
final String profile = this.profile.getValue(args);
if(profile == null) {
throw new OperationFormatException("Required argument --profile is missing.");
}
builder.addNode("profile", profile);
}
final String name = this.name.getValue(ctx.getParsedCommandLine(), true);
for(OperationRequestAddress.Node node : nodePath) {
builder.addNode(node.getType(), node.getName());
}
builder.addNode(type, name);
builder.setOperationName(operation);
final Map<String, CommandArgument> argsMap = loadArguments(ctx, operation);
for(String argName : args.getPropertyNames()) {
if(dependsOnProfile && argName.equals("--profile")) {
continue;
}
if(argsMap == null) {
if(argName.equals(this.name.getFullName())) {
continue;
}
throw new CommandFormatException("Command '" + operation + "' is not expected to have arguments other than " + this.name.getFullName() + ".");
}
final ArgumentWithValue arg = (ArgumentWithValue) argsMap.get(argName);
if(arg == null) {
if(argName.equals(this.name.getFullName())) {
continue;
}
throw new CommandFormatException("Unrecognized argument " + argName + " for command '" + operation + "'.");
}
final String propName;
if(argName.charAt(1) == '-') {
propName = argName.substring(2);
} else {
propName = argName.substring(1);
}
final String valueString = args.getPropertyValue(argName);
ModelNode nodeValue = arg.getValueConverter().fromString(valueString);
builder.getModelNode().get(propName).set(nodeValue);
}
return builder.buildRequest();