use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ReadAttributeHandler method recognizeArguments.
@Override
protected void recognizeArguments(CommandContext ctx) throws CommandFormatException {
super.recognizeArguments(ctx);
final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
if (resolve.isPresent(parsedCmd)) {
ModelNode op = new ModelNode();
op.get("operation").set("read-operation-description");
op.get("name").set("read-attribute");
OperationRequestAddress address = getAddress(ctx, false);
if (address.isEmpty()) {
op.get(Util.ADDRESS).setEmptyList();
} else {
final ModelNode addrNode = op.get(Util.ADDRESS);
for (OperationRequestAddress.Node node : address) {
addrNode.add(node.getType(), node.getName());
}
}
ModelNode returnVal = new ModelNode();
try {
if (ctx.getModelControllerClient() != null) {
returnVal = ctx.getModelControllerClient().execute(op);
}
} catch (IOException e) {
e.printStackTrace();
}
if (returnVal.hasDefined("outcome") && returnVal.get("outcome").asString().equals("success")) {
ModelNode result = returnVal.get("result");
if (result.hasDefined("request-properties")) {
ModelNode properties = result.get("request-properties");
if (!properties.hasDefined("resolve-expressions")) {
throw new OperationFormatException("Resolve Expression argument not available at this location.");
}
}
}
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ReloadHandler method isAdminOnly.
private boolean isAdminOnly(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
boolean legacy = this.adminOnly.isPresent(args) && "TRUE".equalsIgnoreCase(this.adminOnly.getValue(args));
boolean mode = this.startMode.isPresent(args) && ADMIN_ONLY.equalsIgnoreCase(this.startMode.getValue(args));
return mode || legacy;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ReloadHandler method buildRequestWithoutHeaders.
@Override
protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
final ModelNode op = new ModelNode();
if (ctx.isDomainMode()) {
if (useCurrentServerConfig.isPresent(args)) {
throw new CommandFormatException(useCurrentServerConfig.getFullName() + " is not allowed in the domain mode.");
}
if (serverConfig.isPresent(args)) {
throw new CommandFormatException(serverConfig.getFullName() + " is not allowed in the domain mode.");
}
final String hostName = host.getValue(args);
if (hostName == null) {
throw new CommandFormatException("Missing required argument " + host.getFullName());
}
op.get(Util.ADDRESS).add(Util.HOST, hostName);
setBooleanArgument(args, op, restartServers, "restart-servers");
setBooleanArgument(args, op, this.useCurrentDomainConfig, "use-current-domain-config");
setBooleanArgument(args, op, this.useCurrentHostConfig, "use-current-host-config");
setStringValue(args, op, hostConfig, "host-config");
setStringValue(args, op, domainConfig, "domain-config");
} else {
if (host.isPresent(args)) {
throw new CommandFormatException(host.getFullName() + " is not allowed in the standalone mode.");
}
if (useCurrentDomainConfig.isPresent(args)) {
throw new CommandFormatException(useCurrentDomainConfig.getFullName() + " is not allowed in the standalone mode.");
}
if (useCurrentHostConfig.isPresent(args)) {
throw new CommandFormatException(useCurrentHostConfig.getFullName() + " is not allowed in the standalone mode.");
}
if (restartServers.isPresent(args)) {
throw new CommandFormatException(restartServers.getFullName() + " is not allowed in the standalone mode.");
}
if (hostConfig.isPresent(args)) {
throw new CommandFormatException(hostConfig.getFullName() + " is not allowed in the standalone mode.");
}
if (domainConfig.isPresent(args)) {
throw new CommandFormatException(domainConfig.getFullName() + " is not allowed in the standalone mode.");
}
op.get(Util.ADDRESS).setEmptyList();
setBooleanArgument(args, op, this.useCurrentServerConfig, "use-current-server-config");
setStringValue(args, op, serverConfig, "server-config");
}
op.get(Util.OPERATION).set(Util.RELOAD);
setStartMode(ctx, args, op);
return op;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ForHandler method doHandle.
/* (non-Javadoc)
* @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
*/
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
if (ForControlFlow.get(ctx) != null) {
throw new CommandFormatException("for is not allowed while in for block");
}
final BatchManager batchManager = ctx.getBatchManager();
if (batchManager.isBatchActive()) {
throw new CommandFormatException("for is not allowed while in batch mode.");
}
String argsStr = ctx.getArgumentsString();
if (argsStr == null) {
throw new CommandFormatException("The command is missing arguments.");
}
final ParsedCommandLine args = ctx.getParsedCommandLine();
final String varName = this.varName.getOriginalValue(args, true);
int i = argsStr.indexOf(varName);
if (i < 0) {
throw new CommandFormatException("Failed to locate '" + varName + "' in '" + argsStr + "'");
}
i = argsStr.indexOf("in", i + varName.length());
if (i < 0) {
throw new CommandFormatException("Failed to locate 'in' in '" + argsStr + "'");
}
final String requestStr = argsStr.substring(i + 2);
ctx.registerRedirection(new ForControlFlow(ctx, varName, requestStr));
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ArgumentWithoutValue method canAppearNext.
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if (!access.isSatisfied(ctx)) {
return false;
}
ParsedCommandLine args = ctx.getParsedCommandLine();
if (exclusive) {
final Set<String> propertyNames = args.getPropertyNames();
if (propertyNames.isEmpty()) {
final List<String> values = args.getOtherProperties();
if (values.isEmpty()) {
return true;
}
if (index == -1) {
return false;
}
return !(index == 0 && values.size() == 1);
}
if (propertyNames.size() != 1) {
return false;
}
if (args.getLastParsedPropertyName() == null) {
return false;
}
final List<String> values = args.getOtherProperties();
if (!values.isEmpty()) {
return false;
}
// The argument is already there, don't add it.
if (fullName.equals(args.getLastParsedPropertyName())) {
return false;
}
return fullName.startsWith(args.getLastParsedPropertyName()) || (shortName != null && shortName.startsWith(args.getLastParsedPropertyName()));
}
if (isPresent(args)) {
// An argument without value has no value
return false;
}
for (CommandArgument arg : cantAppearAfter) {
if (arg.isPresent(args)) {
return false;
}
}
if (requiredPreceding != null) {
for (CommandArgument arg : requiredPreceding) {
if (arg.isPresent(args)) {
return true;
}
}
return false;
}
return true;
}
Aggregations