use of org.jboss.as.cli.handlers.GenericTypeOperationHandler in project wildfly-core by wildfly.
the class HelpCommand method execute.
@Override
public CommandResult execute(CLICommandInvocation commandInvocation) throws CommandException, InterruptedException {
CommandContext ctx = commandInvocation.getCommandContext();
if (command == null || command.isEmpty()) {
if (commands) {
return listAvailable(commandInvocation);
} else {
ctx.printLine(commandInvocation.getHelpInfo("help"));
}
return CommandResult.SUCCESS;
}
if (commands) {
throw new CommandException("commands option not usable with an argument");
}
if (command.size() > 2) {
throw new CommandException("Command has more than one action");
}
String mainCommand = command.get(0);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < command.size(); i++) {
builder.append(command.get(i));
if (i < command.size() - 1) {
builder.append(" ");
}
}
// An operation?
if (OperationCommandContainer.isOperation(mainCommand)) {
try {
ctx.printLine(getOperationHelp(builder.toString(), commandInvocation.getCommandContext()));
} catch (Exception ex) {
ctx.printLine("Error getting operation help: " + ex.getLocalizedMessage());
}
return CommandResult.SUCCESS;
}
try {
CommandLineParser parser = aeshRegistry.findCommand(mainCommand, builder.toString());
// Special case for generic command that generates the help content on the fly.
if (parser.getProcessedCommand().getCommand() instanceof LegacyCommand) {
CommandHandler handler = ((LegacyCommand) parser.getProcessedCommand().getCommand()).getCommandHandler();
if (handler instanceof GenericTypeOperationHandler) {
try {
((GenericTypeOperationHandler) handler).printDescription(commandInvocation.getCommandContext());
} catch (CommandLineException ex1) {
throw new CommandException(ex1);
}
// We can only rely on handler, handler hides the actual file path
// to its help. eg: remove-batch-line is actually batch-remove-line.txt
} else if (handler instanceof CommandHandlerWithHelp) {
try {
((CommandHandlerWithHelp) handler).displayHelp(commandInvocation.getCommandContext());
} catch (CommandLineException ex1) {
throw new CommandException(ex1);
}
}
} else {
ctx.printLine(parser.printHelp());
}
} catch (CommandNotFoundException ex) {
throw new CommandException("Command " + builder.toString() + " does not exist.");
}
return CommandResult.SUCCESS;
}
use of org.jboss.as.cli.handlers.GenericTypeOperationHandler in project wildfly-core by wildfly.
the class CommandContextImpl method initCommands.
private void initCommands(boolean bootInvoker) throws CommandLineException, CommandLineParserException {
// aesh commands
cmdRegistry.addCommand(new VersionCommand());
cmdRegistry.addCommand(new HelpCommand(cmdRegistry));
if (!bootInvoker) {
cmdRegistry.addCommand(new ConnectCommand());
}
DeploymentCommand.registerDeploymentCommands(this, aeshCommands.getRegistry());
// aesh extensions, for now add grep to make | operator
// usable.
cmdRegistry.addThirdPartyCommand(new Grep(), Collections.emptyMap());
cmdRegistry.registerHandler(new AttachmentHandler(this), "attachment");
cmdRegistry.registerHandler(new PrefixHandler(), "cd", "cn");
if (!bootInvoker) {
cmdRegistry.registerHandler(new ClearScreenHandler(), "clear", "cls");
}
cmdRegistry.registerHandler(new CommandCommandHandler(cmdRegistry), "command");
cmdRegistry.registerHandler(new EchoDMRHandler(), "echo-dmr");
cmdRegistry.registerHandler(new HistoryHandler(), "history");
cmdRegistry.registerHandler(new LsHandler(this), "ls");
cmdRegistry.registerHandler(new ASModuleHandler(this), "module");
cmdRegistry.registerHandler(new PrintWorkingNodeHandler(), "pwd", "pwn");
cmdRegistry.registerHandler(new QuitHandler(), "quit", "q", "exit");
cmdRegistry.registerHandler(new ReadAttributeHandler(this), "read-attribute");
cmdRegistry.registerHandler(new ReadOperationHandler(this), "read-operation");
cmdRegistry.registerHandler(new ConnectionInfoHandler(), "connection-info");
// command-timeout
cmdRegistry.registerHandler(new CommandTimeoutHandler(), "command-timeout");
// variables
cmdRegistry.registerHandler(new SetVariableHandler(), "set");
cmdRegistry.registerHandler(new EchoVariableHandler(), "echo");
cmdRegistry.registerHandler(new UnsetVariableHandler(), "unset");
// deployment
cmdRegistry.registerHandler(new DeployHandler(this), true, "deploy");
cmdRegistry.registerHandler(new UndeployHandler(this), true, "undeploy");
cmdRegistry.registerHandler(new DeploymentInfoHandler(this), true, "deployment-info");
cmdRegistry.registerHandler(new DeploymentOverlayHandler(this), "deployment-overlay");
// batch commands
cmdRegistry.registerHandler(new BatchHandler(this), "batch");
cmdRegistry.registerHandler(new BatchDiscardHandler(), "discard-batch");
cmdRegistry.registerHandler(new BatchListHandler(), "list-batch");
cmdRegistry.registerHandler(new BatchHoldbackHandler(), "holdback-batch");
cmdRegistry.registerHandler(new BatchRunHandler(this), "run-batch");
cmdRegistry.registerHandler(new BatchClearHandler(), "clear-batch");
cmdRegistry.registerHandler(new BatchRemoveLineHandler(), "remove-batch-line");
cmdRegistry.registerHandler(new BatchMoveLineHandler(), "move-batch-line");
cmdRegistry.registerHandler(new BatchEditLineHandler(), "edit-batch-line");
// try-catch
cmdRegistry.registerHandler(new TryHandler(), "try");
cmdRegistry.registerHandler(new CatchHandler(), "catch");
cmdRegistry.registerHandler(new FinallyHandler(), "finally");
cmdRegistry.registerHandler(new EndTryHandler(), "end-try");
// if else
cmdRegistry.registerHandler(new IfHandler(), "if");
cmdRegistry.registerHandler(new ElseHandler(), "else");
cmdRegistry.registerHandler(new EndIfHandler(), "end-if");
// for
cmdRegistry.registerHandler(new ForHandler(), "for");
cmdRegistry.registerHandler(new DoneHandler(), "done");
// data-source
final DefaultCompleter driverNameCompleter = new DefaultCompleter(JDBCDriverNameProvider.INSTANCE);
final GenericTypeOperationHandler dsHandler = new GenericTypeOperationHandler(this, "/subsystem=datasources/data-source", null);
dsHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
// override the add operation with the handler that accepts connection props
final DataSourceAddCompositeHandler dsAddHandler = new DataSourceAddCompositeHandler(this, "/subsystem=datasources/data-source");
dsAddHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
dsHandler.addHandler(Util.ADD, dsAddHandler);
cmdRegistry.registerHandler(dsHandler, dsHandler.getCommandName());
final GenericTypeOperationHandler xaDsHandler = new GenericTypeOperationHandler(this, "/subsystem=datasources/xa-data-source", null);
xaDsHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
// override the xa add operation with the handler that accepts xa props
final XADataSourceAddCompositeHandler xaDsAddHandler = new XADataSourceAddCompositeHandler(this, "/subsystem=datasources/xa-data-source");
xaDsAddHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
xaDsHandler.addHandler(Util.ADD, xaDsAddHandler);
cmdRegistry.registerHandler(xaDsHandler, xaDsHandler.getCommandName());
cmdRegistry.registerHandler(new JDBCDriverInfoHandler(this), "jdbc-driver-info");
// rollout plan
final GenericTypeOperationHandler rolloutPlan = new GenericTypeOperationHandler(this, "/management-client-content=rollout-plans/rollout-plan", null);
rolloutPlan.addValueConverter("content", HeadersArgumentValueConverter.INSTANCE);
rolloutPlan.addValueCompleter("content", RolloutPlanCompleter.INSTANCE);
cmdRegistry.registerHandler(rolloutPlan, rolloutPlan.getCommandName());
// supported but hidden from tab-completion until stable implementation
cmdRegistry.registerHandler(new ArchiveHandler(this), false, "archive");
AtomicReference<EmbeddedProcessLaunch> embeddedServerLaunch = null;
if (!bootInvoker) {
embeddedServerLaunch = EmbeddedControllerHandlerRegistrar.registerEmbeddedCommands(cmdRegistry, this);
cmdRegistry.registerHandler(new ReloadHandler(this, embeddedServerLaunch), "reload");
cmdRegistry.registerHandler(new ShutdownHandler(this, embeddedServerLaunch), "shutdown");
}
cmdRegistry.addCommand(new SecurityCommand(this, embeddedServerLaunch));
if (!bootInvoker) {
registerExtraHandlers();
}
extLoader = new ExtensionsLoader(cmdRegistry, aeshCommands.getRegistry(), this);
}
Aggregations