Search in sources :

Example 1 with GenericTypeOperationHandler

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;
}
Also used : CommandHandlerWithHelp(org.jboss.as.cli.handlers.CommandHandlerWithHelp) CommandContext(org.jboss.as.cli.CommandContext) CommandException(org.aesh.command.CommandException) CommandHandler(org.jboss.as.cli.CommandHandler) CommandNotFoundException(org.aesh.command.CommandNotFoundException) CommandException(org.aesh.command.CommandException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandLineException(org.jboss.as.cli.CommandLineException) GenericTypeOperationHandler(org.jboss.as.cli.handlers.GenericTypeOperationHandler) LegacyCommand(org.jboss.as.cli.impl.aesh.cmd.operation.LegacyCommandContainer.LegacyCommand) CommandLineParser(org.aesh.command.impl.parser.CommandLineParser) CommandNotFoundException(org.aesh.command.CommandNotFoundException)

Example 2 with GenericTypeOperationHandler

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);
}
Also used : ArchiveHandler(org.jboss.as.cli.handlers.ArchiveHandler) ASModuleHandler(org.jboss.as.cli.handlers.module.ASModuleHandler) VersionCommand(org.jboss.as.cli.impl.aesh.cmd.VersionCommand) DeploymentInfoHandler(org.jboss.as.cli.handlers.DeploymentInfoHandler) ElseHandler(org.jboss.as.cli.handlers.ifelse.ElseHandler) DeploymentOverlayHandler(org.jboss.as.cli.handlers.DeploymentOverlayHandler) SecurityCommand(org.jboss.as.cli.impl.aesh.cmd.security.SecurityCommand) BatchHoldbackHandler(org.jboss.as.cli.handlers.batch.BatchHoldbackHandler) DoneHandler(org.jboss.as.cli.handlers.loop.DoneHandler) GenericTypeOperationHandler(org.jboss.as.cli.handlers.GenericTypeOperationHandler) ShutdownHandler(org.jboss.as.cli.handlers.ShutdownHandler) PrefixHandler(org.jboss.as.cli.handlers.PrefixHandler) ReloadHandler(org.jboss.as.cli.handlers.ReloadHandler) EmbeddedProcessLaunch(org.jboss.as.cli.embedded.EmbeddedProcessLaunch) CommandTimeoutHandler(org.jboss.as.cli.handlers.CommandTimeoutHandler) ClearScreenHandler(org.jboss.as.cli.handlers.ClearScreenHandler) XADataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.XADataSourceAddCompositeHandler) JDBCDriverInfoHandler(org.jboss.as.cli.handlers.jca.JDBCDriverInfoHandler) EchoVariableHandler(org.jboss.as.cli.handlers.EchoVariableHandler) BatchRemoveLineHandler(org.jboss.as.cli.handlers.batch.BatchRemoveLineHandler) PrintWorkingNodeHandler(org.jboss.as.cli.handlers.PrintWorkingNodeHandler) EchoDMRHandler(org.jboss.as.cli.handlers.EchoDMRHandler) HelpCommand(org.jboss.as.cli.impl.aesh.cmd.HelpCommand) EndTryHandler(org.jboss.as.cli.handlers.trycatch.EndTryHandler) TryHandler(org.jboss.as.cli.handlers.trycatch.TryHandler) EndTryHandler(org.jboss.as.cli.handlers.trycatch.EndTryHandler) ReadAttributeHandler(org.jboss.as.cli.handlers.ReadAttributeHandler) BatchListHandler(org.jboss.as.cli.handlers.batch.BatchListHandler) ReadOperationHandler(org.jboss.as.cli.handlers.ReadOperationHandler) CommandCommandHandler(org.jboss.as.cli.handlers.CommandCommandHandler) XADataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.XADataSourceAddCompositeHandler) DataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.DataSourceAddCompositeHandler) FinallyHandler(org.jboss.as.cli.handlers.trycatch.FinallyHandler) BatchEditLineHandler(org.jboss.as.cli.handlers.batch.BatchEditLineHandler) CatchHandler(org.jboss.as.cli.handlers.trycatch.CatchHandler) DeployHandler(org.jboss.as.cli.handlers.DeployHandler) QuitHandler(org.jboss.as.cli.handlers.QuitHandler) SetVariableHandler(org.jboss.as.cli.handlers.SetVariableHandler) BatchClearHandler(org.jboss.as.cli.handlers.batch.BatchClearHandler) AttachmentHandler(org.jboss.as.cli.handlers.AttachmentHandler) Grep(org.aesh.extensions.grep.Grep) UndeployHandler(org.jboss.as.cli.handlers.UndeployHandler) BatchRunHandler(org.jboss.as.cli.handlers.batch.BatchRunHandler) LsHandler(org.jboss.as.cli.handlers.LsHandler) BatchHandler(org.jboss.as.cli.handlers.batch.BatchHandler) ConnectionInfoHandler(org.jboss.as.cli.handlers.ConnectionInfoHandler) BatchDiscardHandler(org.jboss.as.cli.handlers.batch.BatchDiscardHandler) EndIfHandler(org.jboss.as.cli.handlers.ifelse.EndIfHandler) HistoryHandler(org.jboss.as.cli.handlers.HistoryHandler) BatchMoveLineHandler(org.jboss.as.cli.handlers.batch.BatchMoveLineHandler) ForHandler(org.jboss.as.cli.handlers.loop.ForHandler) ConnectCommand(org.jboss.as.cli.impl.aesh.cmd.ConnectCommand) UnsetVariableHandler(org.jboss.as.cli.handlers.UnsetVariableHandler) IfHandler(org.jboss.as.cli.handlers.ifelse.IfHandler) EndIfHandler(org.jboss.as.cli.handlers.ifelse.EndIfHandler)

Aggregations

GenericTypeOperationHandler (org.jboss.as.cli.handlers.GenericTypeOperationHandler)2 CommandException (org.aesh.command.CommandException)1 CommandNotFoundException (org.aesh.command.CommandNotFoundException)1 CommandLineParser (org.aesh.command.impl.parser.CommandLineParser)1 Grep (org.aesh.extensions.grep.Grep)1 CommandContext (org.jboss.as.cli.CommandContext)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandHandler (org.jboss.as.cli.CommandHandler)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 EmbeddedProcessLaunch (org.jboss.as.cli.embedded.EmbeddedProcessLaunch)1 ArchiveHandler (org.jboss.as.cli.handlers.ArchiveHandler)1 AttachmentHandler (org.jboss.as.cli.handlers.AttachmentHandler)1 ClearScreenHandler (org.jboss.as.cli.handlers.ClearScreenHandler)1 CommandCommandHandler (org.jboss.as.cli.handlers.CommandCommandHandler)1 CommandHandlerWithHelp (org.jboss.as.cli.handlers.CommandHandlerWithHelp)1 CommandTimeoutHandler (org.jboss.as.cli.handlers.CommandTimeoutHandler)1 ConnectionInfoHandler (org.jboss.as.cli.handlers.ConnectionInfoHandler)1 DeployHandler (org.jboss.as.cli.handlers.DeployHandler)1 DeploymentInfoHandler (org.jboss.as.cli.handlers.DeploymentInfoHandler)1 DeploymentOverlayHandler (org.jboss.as.cli.handlers.DeploymentOverlayHandler)1