if (pos == -1) { Completion.Builder builder = Completion.builder(termPrefix); for (Map.Entry<String, String> command : session.getCommands()) { String name = command.getKey(); if (name.startsWith(termPrefix)) { termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix); } else { completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
/** * The underlying groovu shell used for the REPL. * * @return a groovy shell operating on the session attributes */ public static GroovyShell getGroovyShell(ShellSession session) { GroovyShell shell = (GroovyShell)session.get("shell"); if (shell == null) { CompilerConfiguration config = new CompilerConfiguration(); config.setRecompileGroovySource(true); ShellBinding binding = new ShellBinding(session, session); shell = new GroovyShell(session.getContext().getLoader(), binding, config); session.put("shell", shell); } return shell; }
String name) throws Exception { ShellSession session = (ShellSession)context.getSession(); Repl current = session.getRepl(); if (name != null) { if (name.equals(current.getLanguage().getName())) { } else { Repl found = null; for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.getName().equals(name)) { if (lang.isActive()) { session.setRepl(found); context.provide("Using repl " + name); } else { for (Language lang : session.getContext().getPlugins(Language.class)) { Repl repl = lang.getRepl(); if (repl != null) {
public CommandInvoker<Void, Object> create(ShellSession session) throws CommandNotFoundException, CommandException { LinkedList<CommandInvoker> pipes = new LinkedList<CommandInvoker>(); for (PipeLineFactory current = this;current != null;current = current.next) { Command<?> command = session.getCommand(current.name); if (command == null) { throw new CommandNotFoundException(current.name); } CommandInvoker commandInvoker = command.resolveInvoker(current.rest); if (commandInvoker == null) { throw new CommandNotFoundException(current.name); } pipes.add(commandInvoker); } return new PipeLine(pipes.toArray(new CommandInvoker[pipes.size()])); }
public void testFoo() { assertEquals("ok_mycommand", assertOk("mycommand")); Map<String, String> commands = new HashMap<String, String>(); for (Map.Entry<String, String> entry : session.getCommands()) { commands.put(entry.getKey(), entry.getValue()); } assertTrue("Was expecting " + commands + " to contain mycommand", commands.containsKey("mycommand")); } }
@Override public Completion complete(ParameterDescriptor parameter, String prefix) throws Exception { ShellSession session = (ShellSession)context.getSession(); Completion.Builder builder = Completion.builder(prefix); for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.isActive()) { if (lang.getRepl() != null) { String name = lang.getName(); if (name.startsWith(prefix)) { builder.add(name.substring(prefix.length()), true); } } } } return builder.build(); } }
public void testSessionAccess() { lifeCycle.bindClass("complete", Commands.CompleteWithSession.class); session.put("juu", "juu_value"); CompletionMatch completionMatch = assertComplete("complete foo"); Completion completion = completionMatch.getValue(); assertEquals("foo", completion.getPrefix()); assertEquals(Collections.singleton("juu_value"), completion.getValues()); assertTrue(completion.get("juu_value")); } }
String name) throws Exception { ShellSession session = (ShellSession)context.getSession(); Repl current = session.getRepl(); if (name != null) { if (name.equals(current.getLanguage().getName())) { } else { Repl found = null; for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.getName().equals(name)) { if (lang.isActive()) { session.setRepl(found); context.provide("Using repl " + name); } else { for (Language lang : session.getContext().getPlugins(Language.class)) { Repl repl = lang.getRepl(); if (repl != null) {
@Override public Object getVariable(String name) { if (name.equals("context")) { return proxy; } else { if (session != null) { try { Command<?> cmd = session.getCommand(name); if (cmd != null) { return new PipeLineClosure(new InvocationContextImpl<Object>(proxy), name, cmd); } } catch (CommandException ignore) { // Really ? } return super.getVariable(name); } else { return super.getVariable(name); } } } }
@Override public Completion complete(ParameterDescriptor parameter, String prefix) throws Exception { ShellSession session = (ShellSession)context.getSession(); Completion.Builder builder = Completion.builder(prefix); for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.isActive()) { if (lang.getRepl() != null) { String name = lang.getName(); if (name.startsWith(prefix)) { builder.add(name.substring(prefix.length()), true); } } } } return builder.build(); } }
if (pos == -1) { Completion.Builder builder = Completion.builder(termPrefix); for (Map.Entry<String, String> command : session.getCommands()) { String name = command.getKey(); if (name.startsWith(termPrefix)) { termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix); } else { completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
/** * The underlying groovu shell used for the REPL. * * @return a groovy shell operating on the session attributes */ public static GroovyShell getGroovyShell(ShellSession session) { GroovyShell shell = (GroovyShell)session.get("shell"); if (shell == null) { CompilerConfiguration config = new CompilerConfiguration(); config.setRecompileGroovySource(true); ShellBinding binding = new ShellBinding(session, session); shell = new GroovyShell(session.getContext().getLoader(), binding, config); session.put("shell", shell); } return shell; }
String name) throws Exception { ShellSession session = (ShellSession)context.getSession(); Repl current = session.getRepl(); if (name != null) { if (name.equals(current.getLanguage().getName())) { } else { Repl found = null; for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.getName().equals(name)) { if (lang.isActive()) { session.setRepl(found); context.provide("Using repl " + name); } else { for (Language lang : session.getContext().getPlugins(Language.class)) { Repl repl = lang.getRepl(); if (repl != null) {
public void testReturnedObjectByGroovyScriptIsProduced() throws Exception { lifeCycle.bindGroovy("producer", "return 3"); lifeCycle.bindClass("consumer", Commands.ConsumeInteger.class); Commands.list.clear(); assertOk("producer | consumer"); assertEquals(Arrays.<Object>asList(3), Commands.list); Command<?> producer = session.getCommand("producer"); CommandMatch<?, ?> commandMatch = producer.resolveCommand(""); assertEquals(Object.class, commandMatch.getProducedType()); }
@Override public Completion complete(ParameterDescriptor parameter, String prefix) throws Exception { ShellSession session = (ShellSession)context.getSession(); Completion.Builder builder = Completion.builder(prefix); for (Language lang : session.getContext().getPlugins(Language.class)) { if (lang.isActive()) { if (lang.getRepl() != null) { String name = lang.getName(); if (name.startsWith(prefix)) { builder.add(name.substring(prefix.length()), true); } } } } return builder.build(); } }
if (pos == -1) { Completion.Builder builder = Completion.builder(termPrefix); for (Map.Entry<String, String> command : session.getCommands()) { String name = command.getKey(); if (name.startsWith(termPrefix)) { termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix); } else { completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
/** * The underlying groovu shell used for the REPL. * * @return a groovy shell operating on the session attributes */ public static GroovyShell getGroovyShell(ShellSession session) { GroovyShell shell = (GroovyShell)session.get("shell"); if (shell == null) { CompilerConfiguration config = new CompilerConfiguration(); config.setRecompileGroovySource(true); ShellBinding binding = new ShellBinding(session, session); shell = new GroovyShell(session.getContext().getLoader(), binding, config); session.put("shell", shell); } return shell; }
public void testReturnedObjectByJavaIsProduced() throws Exception { lifeCycle.bindClass("producer", Commands.ReturnInteger.class); lifeCycle.bindClass("consumer", Commands.ConsumeInteger.class); Commands.list.clear(); assertOk("producer | consumer"); assertEquals(Arrays.<Object>asList(3), Commands.list); Command<?> producer = session.getCommand("producer"); CommandMatch<?, ?> commandMatch = producer.resolveCommand(""); assertEquals(Integer.class, commandMatch.getProducedType()); }