org.aesh.command.container.CommandContainer Java Examples
The following examples show how to use
org.aesh.command.container.CommandContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private CommandContainer addCommandContainer(CommandContainer container, boolean checkExistence) throws CommandLineException { CLICommandContainer cliContainer; try { if (container instanceof CLICommandContainer) { cliContainer = (CLICommandContainer) container; } else { cliContainer = wrapContainer(container); } } catch (OptionParserException ex) { throw new CommandLineException(ex); } if (checkExistence) { checkExistence(container.getParser().getProcessedCommand().name()); } reg.addCommand(cliContainer); return cliContainer; }
Example #2
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private CommandContainer disableResolution(CommandLineParser parser) throws OptionParserException, CommandLineParserException { ProcessedCommand cmd = parser.getProcessedCommand(); ProcessedCommandBuilder cmdBuilder = ProcessedCommandBuilder.builder(); CommandContainer convertedContainer = new AeshCommandContainer( CommandLineParserBuilder.builder() .processedCommand(cmdBuilder. activator(cmd.getActivator()). addOptions(ExpressionValueConverter.disableResolution(cmd.getOptions())). aliases(cmd.getAliases()). arguments(ExpressionValueConverter.disableResolution(cmd.getArguments())). argument(ExpressionValueConverter.disableResolution(cmd.getArgument())). command(cmd.getCommand()). description(cmd.description()). name(cmd.name()). populator(cmd.getCommandPopulator()). resultHandler(cmd.resultHandler()). validator(cmd.validator()). create()).create()); return convertedContainer; }
Example #3
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public CommandLineParser findCommand(String name, String line) throws CommandNotFoundException { CommandContainer c = getCommand(name, line); CommandLineParser p = c.getParser(); String[] split = line == null ? new String[0] : line.split(" "); if (split.length > 1) { String sub = split[1]; CommandLineParser child = c.getParser().getChildParser(sub); if (child != null) { // Must make it a CLI thing to properly print the help. if (c instanceof CLICommandContainer) { CLICommandContainer cli = (CLICommandContainer) c; child = cli.wrapParser(child); } p = child; } else { throw new CommandNotFoundException("Command not found " + line, name); } } return p; }
Example #4
Source File: AbstractDynamicCommand.java From galleon with Apache License 2.0 | 5 votes |
public CommandContainer createCommand() throws CommandLineParserException { cmd = buildCommand(); @SuppressWarnings("unchecked") CommandContainer container = new AeshCommandContainer(new AeshCommandLineParser(cmd)); return container; }
Example #5
Source File: HelpCommand.java From galleon with Apache License 2.0 | 5 votes |
@Override protected void runCommand(PmCommandInvocation session) throws CommandExecutionException { if (command == null || command.isEmpty()) { try { session.println(HelpSupport.buildHelp(registry, registry.getAllCommandNames())); } catch (CommandNotFoundException e) { throw new CommandExecutionException(e.getLocalizedMessage()); } } else { StringBuilder builder = new StringBuilder(); for (String str : command) { builder.append(str).append(" "); } String cmd = builder.toString().trim(); try { CommandContainer<?> container = registry.getCommand(command.get(0), null); if (command.size() > 1) { if (container.getParser().getChildParser(command.get(1)) == null) { throw new CommandExecutionException(CliErrors.commandNotFound(cmd)); } } } catch (CommandNotFoundException ex) { throw new CommandExecutionException(CliErrors.commandNotFound(cmd)); } session.println(session.getHelpInfo(cmd)); } }
Example #6
Source File: PatchHelpTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCLICommands() throws Exception { CommandContextImpl ctx = (CommandContextImpl) CommandContextFactory.getInstance().newCommandContext(); AeshCommands commands = ctx.getAeshCommands(); CommandContainer<CLICommandInvocation> container = commands.getRegistry().getCommand("patch", "patch"); HelpSupport.checkCommand(null, container.getParser()); for (CommandLineParser<CLICommandInvocation> child : container.getParser().getAllChildParsers()) { HelpSupport.checkCommand(container.getParser(), child); } }
Example #7
Source File: CLICommandInvocationImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
CLICommandInvocationImpl(CommandContext ctx, CLICommandRegistry registry, ReadlineConsole console, Shell shell, CommandRuntime runtime, CommandInvocationConfiguration config, CommandContainer<CLICommandInvocation> commandContainer) { this.ctx = ctx; this.registry = registry; this.console = console; this.shell = shell; this.runtime = runtime; this.config = config; this.commandContainer = commandContainer; }
Example #8
Source File: CLICommandInvocationBuilder.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public CLICommandInvocation build(CommandRuntime<CLICommandInvocation> runtime, CommandInvocationConfiguration configuration, CommandContainer<CLICommandInvocation> commandContainer) { // We must set a CommandContext that can deal with timeout. // Another approach would have been to set the ctx CommandContext instance // and have the CommandExecutor to set the timeoutContext onto the CLICommandInvocation // but this would require a public setter on the CLICommandInvocationImpl class // something that we don't want. return new CLICommandInvocationImpl(ctx.newTimeoutCommandContext(), registry, console, shell, runtime, configuration, commandContainer); }
Example #9
Source File: AeshCommands.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void addExtraCommands(Iterable<Command> loader, List<String> filter, Set<String> skip, Map<String, String> renaming) throws CommandLineException, CommandLineParserException { for (Command command : loader) { if (filter != null && !filter.isEmpty()) { String name = getRegistry().getCommandName(command); if (!filter.contains(name) || skip.contains(name)) { continue; } } CommandContainer c = getRegistry().addCommand(command, renaming, false); plugins.add(c.getParser().getProcessedCommand().name()); } }
Example #10
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public CommandContainer<CLICommandInvocation> getCommand(String name, String line) throws CommandNotFoundException { if (OperationCommandContainer.isOperation(name)) { return op; } return reg.getCommand(name, line); }
Example #11
Source File: AddUser.java From keycloak with Apache License 2.0 | 4 votes |
private static void printHelp(Command command) throws CommandNotFoundException, CommandRegistryException { CommandRegistry registry = AeshCommandRegistryBuilder.builder().command(command).create(); CommandContainer commandContainer = registry.getCommand(command.getClass().getAnnotation(CommandDefinition.class).name(), null); String help = commandContainer.printHelp(null); System.out.println(help); }
Example #12
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public String getCommandName(Command<CLICommandInvocation> command) throws CommandLineParserException { CommandContainer container = containerBuilder.create(command); return container.getParser().getProcessedCommand().name(); }
Example #13
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public CommandContainer getCommandByAlias(String alias) throws CommandNotFoundException { return reg.getCommandByAlias(alias); }
Example #14
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public CommandContainer addCommand(CommandContainer container) throws CommandLineException { return addCommandContainer(container, true); }
Example #15
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public CommandContainer addThirdPartyCommand(Command<?> command, Map<String, String> renaming) throws CommandLineParserException, CommandLineException { return addCommand(command, renaming, true); }
Example #16
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public CommandContainer addCommand(Command<?> command) throws CommandLineException, CommandLineParserException { return addCommand(command, Collections.emptyMap(), false); }
Example #17
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
CLICommandContainer wrapContainer(CommandContainer commandContainer) throws OptionParserException { return new CLICommandContainer(commandContainer, ctx); }
Example #18
Source File: CLICommandContainer.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public CommandContainer getWrappedContainer() { return container; }
Example #19
Source File: CLICommandContainer.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
CLICommandContainer(CommandContainer<CLICommandInvocation> container, CommandContext ctx) throws OptionParserException { this.container = container; this.ctx = ctx; this.parser = new CLICommandParser(); }