protected Action createNewAction(Session session) { try { return manager.instantiate(actionClass, session.getRegistry()); } catch (Exception e) { throw new RuntimeException("Unable to creation command action " + actionClass.getName(), e); } }
protected Action createNewAction(Session session) { try { return manager.instantiate(actionClass, session.getRegistry()); } catch (Exception e) { throw new RuntimeException("Unable to creation command action " + actionClass.getName(), e); } }
@Override public CommandLine parse(Session session, String command, int cursor) { Object service = session.getRegistry().getService(clazz); if (service instanceof Parser) { return ((Parser) service).parse(session, command, cursor); } throw new IllegalStateException("Could not find specified parser"); }
@Override public CommandLine parse(Session session, String command, int cursor) { Object service = session.getRegistry().getService(clazz); if (service instanceof Parser) { return ((Parser) service).parse(session, command, cursor); } throw new IllegalStateException("Could not find specified parser"); }
@Override public String preprocess(Session session, CommandLine commandLine) { Object service = session.getRegistry().getService(clazz); if (service instanceof Parser) { return ((Parser) service).preprocess(session, commandLine); } throw new IllegalStateException("Could not find specified parser"); } }
@Override public String preprocess(Session session, CommandLine commandLine) { Object service = session.getRegistry().getService(clazz); if (service instanceof Parser) { return ((Parser) service).preprocess(session, commandLine); } throw new IllegalStateException("Could not find specified parser"); } }
protected void discoverCommands(Session session, ClassLoader cl, String resource) throws IOException, ClassNotFoundException { Manager manager = new ManagerImpl(session.getRegistry(), session.getFactory().getRegistry(), true); Enumeration<URL> urls = cl.getResources(resource); while (urls.hasMoreElements()) { URL url = urls.nextElement(); BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); String line = r.readLine(); while (line != null) { line = line.trim(); if (line.length() > 0 && line.charAt(0) != '#') { final Class<?> actionClass = cl.loadClass(line); manager.register(actionClass); } line = r.readLine(); } r.close(); } }
@Override public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) { Object service = session.getRegistry().getService(clazz); if (service instanceof Completer) { ((Completer) service).completeCandidates(session, commandLine, candidates); } } }
protected void discoverCommands(Session session, ClassLoader cl, String resource) throws IOException, ClassNotFoundException { Manager manager = new ManagerImpl(session.getRegistry(), session.getFactory().getRegistry(), true); Enumeration<URL> urls = cl.getResources(resource); while (urls.hasMoreElements()) { URL url = urls.nextElement(); BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); String line = r.readLine(); while (line != null) { line = line.trim(); if (line.length() > 0 && line.charAt(0) != '#') { final Class<?> actionClass = cl.loadClass(line); manager.register(actionClass); } line = r.readLine(); } r.close(); } }
@Override public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) { Object service = session.getRegistry().getService(clazz); if (service instanceof Completer) { ((Completer) service).completeCandidates(session, commandLine, candidates); } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { Object service = session.getRegistry().getService(clazz); if (service instanceof Completer) { return ((Completer) service).complete(session, commandLine, candidates); } return -1; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { Object service = session.getRegistry().getService(clazz); if (service instanceof Completer) { return ((Completer) service).complete(session, commandLine, candidates); } return -1; }
private Set<Command> getCommands(Session session, String path) { // TODO: this is not really clean List<Command> commands = session.getRegistry().getCommands(); String subshell = (String) session.get(Session.SUBSHELL); String completionMode = (String) session.get(Session.COMPLETION_MODE); Set<Command> matchingCommands = new HashSet<>(); for (Command command : commands) { String name = command.getScope() + ":" + command.getName(); if (command != null && !name.startsWith(path)) { continue; } if (completionMode != null && completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL)) { // filter the help only for "global" commands if (subshell == null || subshell.trim().isEmpty()) { if (!name.startsWith(Session.SCOPE_GLOBAL)) { continue; } } } if (completionMode != null && (completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL) || completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_FIRST))) { // filter the help only for commands local to the subshell if (!name.startsWith(subshell)) { continue; } } matchingCommands.add(command); } return matchingCommands; }
private Set<Command> getCommands(Session session, String path) { // TODO: this is not really clean List<Command> commands = session.getRegistry().getCommands(); String subshell = (String) session.get(Session.SUBSHELL); String completionMode = (String) session.get(Session.COMPLETION_MODE); Set<Command> matchingCommands = new HashSet<>(); for (Command command : commands) { String name = command.getScope() + ":" + command.getName(); if (command != null && !name.startsWith(path)) { continue; } if (completionMode != null && completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL)) { // filter the help only for "global" commands if (subshell == null || subshell.trim().isEmpty()) { if (!name.startsWith(Session.SCOPE_GLOBAL)) { continue; } } } if (completionMode != null && (completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL) || completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_FIRST))) { // filter the help only for commands local to the subshell if (!name.startsWith(subshell)) { continue; } } matchingCommands.add(command); } return matchingCommands; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // TODO: optimize List<Command> list = session.getRegistry().getCommands(); Set<String> names = new HashSet<>(); for (Command command : list) { names.add(command.getScope() + ":" + command.getName()); names.add(command.getName()); } int res = new StringsCompleter(names).complete(session, commandLine, candidates); Collections.sort(candidates); return res; }
public String getHelp(final Session session, String path) { if (path == null) { path = "%root%"; } Map<String,String> props = new HashMap<>(); props.put("data", "${" + path + "}"); final List<HelpProvider> providers = session.getRegistry().getServices(HelpProvider.class); InterpolationHelper.performSubstitution(props, key -> { for (HelpProvider hp : providers) { String result = hp.getHelp(session, key); if (result != null) { return removeNewLine(result); } } return null; }); return props.get("data"); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // TODO: optimize List<Command> list = session.getRegistry().getCommands(); Set<String> names = new HashSet<>(); for (Command command : list) { names.add(command.getScope() + ":" + command.getName()); names.add(command.getName()); } int res = new StringsCompleter(names).complete(session, commandLine, candidates); Collections.sort(candidates); return res; }
public String getHelp(final Session session, String path) { if (path == null) { path = "%root%"; } Map<String,String> props = new HashMap<>(); props.put("data", "${" + path + "}"); final List<HelpProvider> providers = session.getRegistry().getServices(HelpProvider.class); InterpolationHelper.performSubstitution(props, key -> { for (HelpProvider hp : providers) { String result = hp.getHelp(session, key); if (result != null) { return removeNewLine(result); } } return null; }); return props.get("data"); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { String arg = commandLine.getCursorArgument(); int pos = commandLine.getArgumentPosition(); CommandLine cmdLine = new DefaultParser().parse(session, arg, pos); Completer completer = session.getRegistry().getService(CommandsCompleter.class); List<String> cands = new ArrayList<>(); int res = completer.complete(session, cmdLine, cands); for (String cand : cands) { candidates.add(arg.substring(0, cmdLine.getBufferPosition() - cmdLine.getArgumentPosition()) + cand); } if (res >= 0) { res += commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } return res; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { String arg = commandLine.getCursorArgument(); int pos = commandLine.getArgumentPosition(); CommandLine cmdLine = new DefaultParser().parse(session, arg, pos); Completer completer = session.getRegistry().getService(CommandsCompleter.class); List<String> cands = new ArrayList<>(); int res = completer.complete(session, cmdLine, cands); for (String cand : cands) { candidates.add(arg.substring(0, cmdLine.getBufferPosition() - cmdLine.getArgumentPosition()) + cand); } if (res >= 0) { res += commandLine.getBufferPosition() - commandLine.getArgumentPosition(); } return res; }