Class GroovyshOptions.Builder

java.lang.Object
org.apache.groovy.groovysh.GroovyshOptions.Builder
Enclosing class:
GroovyshOptions

@Incubating public static final class GroovyshOptions.Builder extends Object
Builder for GroovyshOptions.
Since:
7.0.0
  • Method Details

    • compilerConfiguration

      public GroovyshOptions.Builder compilerConfiguration(CompilerConfiguration compilerConfiguration)
      Sets the compiler configuration used when no engine(GroovyEngine) is supplied.
      Parameters:
      compilerConfiguration - the configuration, or null for the default
      Returns:
      this builder
    • engine

      public GroovyshOptions.Builder engine(GroovyEngine engine)
      Supplies a pre-built engine. When set, compilerConfiguration(CompilerConfiguration) is not used to construct a second engine.
      Parameters:
      engine - the engine
      Returns:
      this builder
    • bindings

      public GroovyshOptions.Builder bindings(Map<String,?> bindings)
      Replaces the binding variables that will be installed on the engine.
      Parameters:
      bindings - variables to install; null is treated as empty
      Returns:
      this builder
    • binding

      public GroovyshOptions.Builder binding(String name, Object value)
      Adds a single binding variable.
      Parameters:
      name - variable name, must not be null
      value - variable value
      Returns:
      this builder
    • groups

      public GroovyshOptions.Builder groups(org.jline.shell.CommandGroup... groups)
      Appends command groups. Mirrors ShellBuilder.groups(CommandGroup...).
      Parameters:
      groups - groups to append; null entries are rejected
      Returns:
      this builder
    • groups

      public GroovyshOptions.Builder groups(Iterable<? extends org.jline.shell.CommandGroup> groups)
      Appends command groups.
      Parameters:
      groups - groups to append; null is ignored
      Returns:
      this builder
    • prompt

      public GroovyshOptions.Builder prompt(String prompt)
      Sets a fixed prompt. Mirrors ShellBuilder.prompt(String).
      Parameters:
      prompt - the prompt text, or null for "groovy> "
      Returns:
      this builder
    • prompt

      public GroovyshOptions.Builder prompt(Supplier<String> prompt)
      Sets the prompt supplier, called once per REPL iteration. Mirrors ShellBuilder.prompt(Supplier).
      Parameters:
      prompt - the supplier, or null for "groovy> "
      Returns:
      this builder
    • rightPrompt

      public GroovyshOptions.Builder rightPrompt(String rightPrompt)
      Sets a fixed right-hand prompt. Mirrors ShellBuilder.rightPrompt(String).
      Parameters:
      rightPrompt - the prompt text, or null for none
      Returns:
      this builder
    • rightPrompt

      public GroovyshOptions.Builder rightPrompt(Supplier<String> rightPrompt)
      Sets the right-hand prompt supplier. Mirrors ShellBuilder.rightPrompt(Supplier).
      Parameters:
      rightPrompt - the supplier, or null for none
      Returns:
      this builder
    • resultHandler

      public GroovyshOptions.Builder resultHandler(GroovyshOptions.ResultHandler resultHandler)
      Sets the result handler.
      Parameters:
      resultHandler - the handler, or null for the default printer
      Returns:
      this builder
    • errorHandler

      public GroovyshOptions.Builder errorHandler(GroovyshOptions.ErrorHandler errorHandler)
      Sets the error handler.
      Parameters:
      errorHandler - the handler, or null for groovysh's own trace
      Returns:
      this builder
    • showBanner

      public GroovyshOptions.Builder showBanner(boolean showBanner)
      Sets whether the groovysh banner is printed.
      Parameters:
      showBanner - false to suppress the banner
      Returns:
      this builder
    • terminal

      public GroovyshOptions.Builder terminal(org.jline.terminal.Terminal terminal)
      Supplies a terminal instead of letting Main build one from CLI flags. Mirrors ShellBuilder.terminal(Terminal).
      Parameters:
      terminal - the terminal, or null to build the default
      Returns:
      this builder
    • historyFile

      public GroovyshOptions.Builder historyFile(Path historyFile)
      Sets the history file. Mirrors ShellBuilder.historyFile(Path).
      Parameters:
      historyFile - the file, or null for groovysh's own
      Returns:
      this builder
    • onReaderReady

      public GroovyshOptions.Builder onReaderReady(Consumer<org.jline.reader.LineReader> onReaderReady)
      Registers a callback invoked once the reader is wired, immediately before the REPL starts. Mirrors ShellBuilder.onReaderReady(Consumer).
      Parameters:
      onReaderReady - the callback, or null for none
      Returns:
      this builder
    • onReaderReady

      public GroovyshOptions.Builder onReaderReady(BiConsumer<org.jline.reader.LineReader,org.apache.groovy.groovysh.jline.GroovySystemRegistry> onReaderReady)
      Registers a callback invoked once the reader and the command registry are both wired, immediately before the REPL starts. Mirrors ShellBuilder.onReaderReady(BiConsumer).

      This is the hook for completion. groovysh has already assigned reader.setCompleter(registry.completer()) by the time the callback runs, so an embedder contributing its own completion wraps that, for example reader.setCompleter(new AggregateCompleter(registry.completer(), mine)). Candidates from an AggregateCompleter are merged, so a completer added this way supplements groovysh's rather than replacing it; assign a completer of your own to replace it outright.

      Parameters:
      onReaderReady - the callback, or null for none
      Returns:
      this builder
    • build

      public GroovyshOptions build()
      Builds an immutable options object.
      Returns:
      the options