use of org.wildfly.core.cli.command.DMRCommand in project wildfly-core by wildfly.
the class DeployHandler method buildRequestWithoutHeaders.
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
ParsedCommandLine args = ctx.getParsedCommandLine();
boolean l = this.l.isPresent(args);
if (!args.hasProperties() || l) {
throw new CommandFormatException("No Option");
}
final boolean unmanaged = this.unmanaged.isPresent(args);
final String path = this.path.getValue(args);
final String name = this.name.getValue(args);
final String rtName = this.rtName.getValue(args);
final String url = this.url.getValue(args);
final boolean force = this.force.isPresent(args);
final boolean disabled = this.disabled.isPresent(args);
final boolean enabled = this.enabled.isPresent(args);
final String serverGroups = this.serverGroups.getValue(args);
final boolean allServerGroups = this.allServerGroups.isPresent(args);
final ModelNode headersNode = headers.toModelNode(ctx);
if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
throw new CommandFormatException("--headers option has wrong value '" + headersNode + "'");
}
if (path == null && url == null) {
if (name == null) {
throw new CommandFormatException("Filesystem path, --url or --name is " + " required.");
}
if (name.equals(ALL)) {
if (force || disabled) {
throw new CommandFormatException("force and disabled can't be used " + "when deploying all disabled deployments");
}
EnableAllCommand command = new EnableAllCommand(ctx);
command.allServerGroups = allServerGroups;
command.headers = headersNode;
command.serverGroups = serverGroups;
return command.buildRequest(ctx);
} else {
EnableCommand command = new EnableCommand(ctx);
command.allServerGroups = allServerGroups;
command.headers = headersNode;
command.serverGroups = serverGroups;
command.name = name;
return command.buildRequest(ctx);
}
}
if (path != null) {
if (url != null) {
throw new CommandFormatException("Filesystem path and --url can't be used together.");
}
File f = new File(path);
DMRCommand c;
if (DeployArchiveCommand.isCliArchive(f)) {
DeployArchiveCommand command = new DeployArchiveCommand(ctx);
command.file = f;
command.script = this.script.getValue(args);
c = command;
} else {
DeployFileCommand command = new DeployFileCommand(ctx, REPLACE_OPTION);
command.allServerGroups = allServerGroups;
command.disabled = disabled;
command.enabled = enabled;
command.file = f;
command.replace = force;
command.headers = headersNode;
command.name = name;
command.runtimeName = rtName;
command.serverGroups = serverGroups;
command.unmanaged = unmanaged;
c = command;
}
return c.buildRequest(ctx);
}
if (url != null) {
if (path != null) {
throw new CommandFormatException("Filesystem path and --url can't be " + "used together.");
}
DeployUrlCommand command = new DeployUrlCommand(ctx, REPLACE_OPTION);
command.allServerGroups = allServerGroups;
command.disabled = disabled;
command.enabled = enabled;
try {
command.deploymentUrl = new URL(url);
} catch (MalformedURLException ex) {
throw new CommandFormatException(ex);
}
command.replace = force;
command.headers = headersNode;
command.runtimeName = rtName;
command.serverGroups = serverGroups;
return command.buildRequest(ctx);
}
throw new CommandFormatException("Invalid Options.");
}
use of org.wildfly.core.cli.command.DMRCommand in project wildfly-core by wildfly.
the class CommandContextImpl method buildAeshCommandRequest.
public OperationCommand.HandledRequest buildAeshCommandRequest(ParsedCommandLine parsedCmd, boolean batchMode) throws CommandFormatException {
AeshCommands.CLIExecution execution = null;
try {
execution = aeshCommands.newExecutions(parsedCmd).get(0);
// We are not going to execute the command, it must be populated explicitly
// to have options injected in Command instance.
execution.populateCommand();
} catch (CommandLineParserException | OptionValidatorException | IOException ex) {
throw new CommandFormatException(ex);
} catch (CommandNotFoundException ex) {
throw new OperationFormatException("No command handler for '" + parsedCmd.getOperationName() + "'.");
}
BatchCompliantCommand bc = execution.getBatchCompliant();
if (batchMode) {
if (bc == null) {
throw new OperationFormatException("The command is not allowed in a batch.");
}
Batch batch = getBatchManager().getActiveBatch();
return new OperationCommand.HandledRequest(bc.buildRequest(this, batch.getAttachments()), null);
} else {
DMRCommand dmr = execution.getDMRCompliant();
if (dmr == null) {
throw new OperationFormatException("The command does not translate to an operation request.");
}
return new OperationCommand.HandledRequest(dmr.buildRequest(this), null);
}
}
Aggregations