Package org.codehaus.groovy.tools.shell

Examples of org.codehaus.groovy.tools.shell.Groovysh


   * @param args Command line arguments
   * @throws Exception
   */
  public static void main (String[] args) throws Exception {
    System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
    Groovysh shell = new Groovysh();

    // Install our error hook (exception handling)
    shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));

    CommandRegistry registry = shell.getRegistry();
    @SuppressWarnings("unchecked")
    Iterator<Command> iterator = registry.iterator();
    while (iterator.hasNext()) {
      Command command = iterator.next();
      if (!commandsToKeep.contains(command.getName())) {
        iterator.remove();
        // remove from "names" set to avoid duplicate error.
        registry.remove(command);
      }
    }

    shell.register(new HelpCommand(shell));
    shell.register(new SetCommand(shell));
    shell.register(new ShowCommand(shell));
    shell.register(new CreateCommand(shell));
    shell.register(new DeleteCommand(shell));
    shell.register(new UpdateCommand(shell));
    shell.register(new CloneCommand(shell));
    shell.register(new SubmissionCommand(shell));

    // Configure shared shell io object
    setIo(shell.getIo());

    // We're running in batch mode by default
    setInteractive(false);

    // Let's see if user do have resource file with initial commands that he
    // would like to apply.
    String homeDir = System.getProperty(Constants.PROP_HOMEDIR);
    File rcFile = new File(homeDir, RC_FILE);

    if(rcFile.exists()) {
      printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADRC, RC_FILE);
      interpretFileContent(rcFile, shell);
      printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC);
    }

    if (args.length == 0) {
      // Interactive mode:
      getIo().setVerbosity(Verbosity.QUIET);
      printlnResource(Constants.RES_SQOOP_SHELL_BANNER);
      println();

      // Switch to interactive mode
      setInteractive(true);
      shell.run(args);

    } else {
      // Batch mode (with a script file):
      File script = new File(args[0]);
      if (!script.isAbsolute()) {
View Full Code Here


        io.out.println();
        io.out.println("         \\,,,/");
        io.out.println("         (o o)");
        io.out.println("-----oOOo-(_)-oOOo-----");

        final Groovysh groovy = new Groovysh();
        groovy.setResultHook(new NullResultHookClosure(groovy));

        // Gremlin + Titan imports
        for (String i : ConsoleSetup.getAllImportStatements()) {
            groovy.execute(i);
        }

        groovy.setResultHook(new ResultHookClosure(groovy, io, resultPrompt));
        groovy.setHistory(new History());

        final InteractiveShellRunner runner = new InteractiveShellRunner(groovy, new PromptClosure(groovy, inputPrompt));
        runner.setErrorHandler(new ErrorHookClosure(runner, io));
        try {
            runner.setHistory(new History(new File(System.getProperty("user.home") + "/" + HISTORY_FILE)));
View Full Code Here

        // this being remote means no jline capability is available
        System.setProperty("jline.terminal", UnsupportedTerminal.class.getName());
        Terminal.resetTerminal();

        Groovysh shell = createShell(stdin, stdout, stderr);
        return shell.run(args.toArray(new String[args.size()]));
    }
View Full Code Here

                r.register(GroovyshCommand.class.getResource("commands.xml"));

                return null;
            }
        };
        Groovysh shell = new Groovysh(cl, binding, io, registrar);
        shell.getImports().add("import hudson.model.*");

        // defaultErrorHook doesn't re-throw IOException, so ShellRunner in
        // Groovysh will keep looping forever if we don't terminate when the
        // channel is closed
        final Closure originalErrorHook = shell.getErrorHook();
        shell.setErrorHook(new Closure(shell, shell) {
            public Object doCall(Object[] args) throws ChannelClosedException {
                if (args.length == 1 && args[0] instanceof ChannelClosedException) {
                    throw (ChannelClosedException)args[0];
                }

View Full Code Here

TOP

Related Classes of org.codehaus.groovy.tools.shell.Groovysh

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.