org.aesh.command.CommandNotFoundException Java Examples
The following examples show how to use
org.aesh.command.CommandNotFoundException.
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: AeshCommands.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private CLIExecutor newExecutor(String line) throws CommandFormatException, IOException, CommandNotFoundException { CLIExecutor exe; // The Aesh parser doesn't handle \\n // So remove them all. This has been seen in MultipleLinesCommandsTestCase test String sep = "\\" + Util.LINE_SEPARATOR; if (line.contains(sep)) { String[] split = line.split("\\" + sep); StringBuilder builder = new StringBuilder(); for (String ss : split) { builder.append(ss + " "); } line = builder.toString(); } try { exe = new CLIExecutor(processor.buildExecutor(line)); } catch (CommandLineParserException | OptionValidatorException | CommandValidatorException ex) { throw new CommandFormatException(ex.getLocalizedMessage()); } return exe; }
Example #2
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public List<String> getAvailableAeshCommands() { List<String> lst = new ArrayList<>(); for (String c : getAllCommandNames()) { CommandLineParser cmdParser; try { cmdParser = findCommand(c, null); } catch (CommandNotFoundException ex) { continue; } CommandActivator activator = cmdParser.getProcessedCommand().getActivator(); if (activator == null || activator.isActivated(new ParsedCommand(cmdParser.getProcessedCommand()))) { lst.add(c); } } return lst; }
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: HelpSupport.java From galleon with Apache License 2.0 | 5 votes |
public static String getToolHelp(PmSession session, CommandRegistry<? extends CommandInvocation> registry) throws CommandNotFoundException { StringBuilder sb = new StringBuilder(); sb.append("== DEFAULT MODE ==").append(Config.getLineSeparator()); session.getToolModes().setMode(ToolModes.Mode.NOMINAL); sb.append(buildHelp(registry, registry.getAllCommandNames(), false)); sb.append(Config.getLineSeparator()).append("== EDIT MODE ==").append(Config.getLineSeparator()); session.getToolModes().setMode(ToolModes.Mode.EDIT); sb.append(buildHelp(registry, registry.getAllCommandNames(), true)); return sb.toString(); }
Example #5
Source File: HelpCommand.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private CommandResult listAvailable(CLICommandInvocation commandInvocation) throws CommandException, InterruptedException { CommandContext ctx = commandInvocation.getCommandContext(); List<String> lst = new ArrayList<>(); // First aesh for (String c : aeshRegistry.getAllCommandNames()) { CommandLineParser<? extends Command> cmdParser; try { cmdParser = aeshRegistry.findCommand(c, null); } catch (CommandNotFoundException ex) { continue; } CommandActivator activator = cmdParser.getProcessedCommand().getActivator(); if (activator == null || activator.isActivated(new ParsedCommand(cmdParser.getProcessedCommand()))) { if (cmdParser.isGroupCommand()) { for (CommandLineParser child : cmdParser.getAllChildParsers()) { CommandActivator childActivator = child.getProcessedCommand().getActivator(); if (childActivator == null || childActivator.isActivated(new ParsedCommand(child.getProcessedCommand()))) { lst.add(c + " " + child.getProcessedCommand().name()); } } } else { lst.add(c); } } } ctx.printLine("Commands available in the current context:"); print(lst, ctx); ctx.printLine("To read a description of a specific command execute 'help <command name>'."); return CommandResult.SUCCESS; }
Example #6
Source File: CLICommandInvocationImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Executor<? extends CommandInvocation> buildExecutor(String line) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException { return runtime.buildExecutor(line); }
Example #7
Source File: CLICommandInvocationImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void executeCommand(String input) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException, IOException { runtime.executeCommand(input); }
Example #8
Source File: CLICommandInvocationImpl.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public String getHelpInfo(String commandName) { try { // This parser knows how to print help content. CommandLineParser parser = registry.findCommand(commandName, commandName); if (parser != null) { return parser.printHelp(); } } catch (CommandNotFoundException ex) { Logger.getLogger(CLICommandInvocationImpl.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
Example #9
Source File: AeshCommands.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public List<CLIExecution> newExecutions(ParsedCommandLine line) throws CommandFormatException, IOException, CommandNotFoundException { String l = line.getSubstitutedLine(); // That is a legacy behavior, lowerCase command name. if (line.getFormat() != OperationFormat.INSTANCE) { String name = line.getOperationName(); l = name.toLowerCase() + l.substring(name.length()); } CLIExecutor exe = newExecutor(l); if (exe.getExecutions().isEmpty()) { throw new CommandFormatException("Invalid command " + line.getOriginalLine()); } return exe.getExecutions(); }
Example #10
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public boolean isLegacyCommand(String name) { try { CLICommandContainer c = (CLICommandContainer) getCommand(name, name); return c.getWrappedContainer() instanceof LegacyCommandContainer; } catch (CommandNotFoundException ex) { return false; } }
Example #11
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 #12
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkExistence(String name) throws RegisterHandlerException { try { reg.getCommand(name, name); throw new RegisterHandlerException(name); } catch (CommandNotFoundException ex) { // XXX OK expected. //check in commands handler. if (getCommandHandler(name) != null) { throw new RegisterHandlerException(name); } } }
Example #13
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 #14
Source File: HelpSupport.java From galleon with Apache License 2.0 | 5 votes |
private static String buildHelp(CommandRegistry<? extends CommandInvocation> registry, Set<String> commands, boolean footer) throws CommandNotFoundException { TreeMap<CommandDomain, Set<String>> groupedCommands = new TreeMap<>(); for (String command : commands) { CommandDomain group = CommandDomain.getDomain(registry.getCommand(command, null).getParser().getCommand()); String commandTree = getCommandTree(registry, command); if (group == null) { group = CommandDomain.OTHERS; } Set<String> currentDescriptions = groupedCommands.get(group); if (currentDescriptions == null) { currentDescriptions = new TreeSet<>(); groupedCommands.put(group, currentDescriptions); } currentDescriptions.add(commandTree); } StringBuilder sb = new StringBuilder(); for (Map.Entry<CommandDomain, Set<String>> groupedCommand : groupedCommands.entrySet()) { sb.append(Config.getLineSeparator()); sb.append("== ").append(groupedCommand.getKey().getDescription()).append(" =="); sb.append(Config.getLineSeparator()); for (String description : groupedCommand.getValue()) { sb.append(description); sb.append(Config.getLineSeparator()); } } if (footer) { sb.append(getHelpFooter()); } return sb.toString(); }
Example #15
Source File: HelpSupport.java From galleon with Apache License 2.0 | 5 votes |
public static List<String> getAvailableCommands(CommandRegistry<? extends CommandInvocation> registry, boolean includeChilds, boolean onlyEnabled) { List<String> lst = new ArrayList<>(); // First aesh for (String c : registry.getAllCommandNames()) { CommandLineParser<? extends CommandInvocation> cmdParser; try { cmdParser = registry.getCommand(c, null).getParser(); } catch (CommandNotFoundException ex) { continue; } CommandActivator activator = cmdParser.getProcessedCommand().getActivator(); if (activator == null || activator.isActivated(new ParsedCommand(cmdParser.getProcessedCommand()))) { if (cmdParser.isGroupCommand() && includeChilds) { for (CommandLineParser child : cmdParser.getAllChildParsers()) { CommandActivator childActivator = child.getProcessedCommand().getActivator(); if (!onlyEnabled || (childActivator == null || childActivator.isActivated(new ParsedCommand(child.getProcessedCommand())))) { lst.add(c + " " + child.getProcessedCommand().name()); } } } else { lst.add(c); } } } return lst; }
Example #16
Source File: CliWrapper.java From galleon with Apache License 2.0 | 5 votes |
public void execute(String str) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException, IOException { out.reset(); runtime.executeCommand(str); }
Example #17
Source File: HelpCommand.java From galleon with Apache License 2.0 | 4 votes |
@Override public void complete(PmCompleterInvocation completerInvocation) { HelpCommand cmd = (HelpCommand) completerInvocation.getCommand(); String mainCommand = null; if (cmd.command != null) { if (cmd.command.size() > 1) { // Nothing to add. return; } mainCommand = cmd.command.get(0); } String buff = completerInvocation.getGivenCompleteValue(); List<String> allAvailable = HelpSupport.getAvailableCommands(cmd.registry, false, true); List<String> candidates = new ArrayList<>(); if (mainCommand == null) { if (buff == null || buff.isEmpty()) { candidates.addAll(allAvailable); } else { for (String c : allAvailable) { if (c.startsWith(buff)) { candidates.add(c); } } } } else { try { CommandLineParser<? extends CommandInvocation> p = cmd.registry.getCommand(mainCommand, null).getParser(); for (CommandLineParser child : p.getAllChildParsers()) { if (child.getProcessedCommand().name().startsWith(buff)) { CommandActivator childActivator = child.getProcessedCommand().getActivator(); if (childActivator == null || childActivator.isActivated(new ParsedCommand(child.getProcessedCommand()))) { candidates.add(child.getProcessedCommand().name()); } } } } catch (CommandNotFoundException ex) { // XXX OK, no command, no sub command. } } Collections.sort(candidates); completerInvocation.addAllCompleterValues(candidates); }
Example #18
Source File: CliShellPmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Executor<? extends CommandInvocation> buildExecutor(String string) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException { return delegate.buildExecutor(string); }
Example #19
Source File: CliShellPmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@Override public void executeCommand(String string) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException, IOException { delegate.executeCommand(string); }
Example #20
Source File: InteractivePmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Executor<? extends CommandInvocation> buildExecutor(String line) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException { return delegate.buildExecutor(line); }
Example #21
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 #22
Source File: CLICommandRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public List<CommandLineParser<?>> getChildCommandParsers(String parent) throws CommandNotFoundException { return reg.getChildCommandParsers(parent); }
Example #23
Source File: InteractivePmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@Override public void executeCommand(String input) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException, IOException { delegate.executeCommand(input); }
Example #24
Source File: OutputPmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Executor<? extends CommandInvocation> buildExecutor(String line) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException { return delegate.buildExecutor(line); }
Example #25
Source File: OutputPmCommandInvocation.java From galleon with Apache License 2.0 | 4 votes |
@Override public void executeCommand(String input) throws CommandNotFoundException, CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException, IOException { delegate.executeCommand(input); }
Example #26
Source File: HelpSupport.java From galleon with Apache License 2.0 | 4 votes |
private static String getCommandTree(CommandRegistry<? extends CommandInvocation> registry, String command) throws CommandNotFoundException { CommandLineParser<? extends CommandInvocation> cmdParser = registry.getCommand(command, null).getParser(); StringBuilder sb = new StringBuilder(); ProcessedCommand<? extends Command<? extends CommandInvocation>, ? extends CommandInvocation> processedCommand = cmdParser.getProcessedCommand(); sb.append(processedCommand.name()); if (processedCommand.hasArguments() || processedCommand.hasArgument()) { sb.append(" <arg>"); } sb.append(" ").append(trimDescription(processedCommand.description())); sb.append(getCommandOptions(processedCommand, 0)); if (!cmdParser.getAllChildParsers().isEmpty()) { List<? extends CommandLineParser<? extends CommandInvocation>> allChildParsers = cmdParser.getAllChildParsers(); allChildParsers.sort((Comparator<CommandLineParser<? extends CommandInvocation>>) (o1, o2) -> { ProcessedCommand<? extends Command<? extends CommandInvocation>, ? extends CommandInvocation> pc1 = o1.getProcessedCommand(); ProcessedCommand<? extends Command<? extends CommandInvocation>, ? extends CommandInvocation> pc2 = o2.getProcessedCommand(); return pc1.name().compareTo(pc2.name()); }); for (CommandLineParser<? extends CommandInvocation> childParser : allChildParsers) { ProcessedCommand<? extends Command<? extends CommandInvocation>, ? extends CommandInvocation> childProcessedCommand = childParser.getProcessedCommand(); sb.append(Config.getLineSeparator()).append(" "); sb.append(childProcessedCommand.name()); if (childProcessedCommand.hasArguments() || childProcessedCommand.hasArgument()) { sb.append(" <arg>"); } sb.append(" ").append(trimDescription(childProcessedCommand.description())); sb.append(getCommandOptions(childProcessedCommand, 4)); } } return sb.toString(); }
Example #27
Source File: HelpSupport.java From galleon with Apache License 2.0 | 4 votes |
public static String buildHelp(CommandRegistry<? extends CommandInvocation> registry, Set<String> commands) throws CommandNotFoundException { return buildHelp(registry, commands, true); }
Example #28
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); }