or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

console-integration.mddocumentation-inspection.mdindex.mdinteractive-commands.mdscript-engine.md
tile.json

tessl/maven-org-apache-groovy--groovy-groovysh

Interactive command-line shell (REPL) for Apache Groovy with scripting engine and rich command system

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.groovy/groovy-groovysh@5.0.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-groovy--groovy-groovysh@5.0.0

index.mddocs/

Groovy Shell (groovysh)

Apache Groovy's interactive command-line shell (REPL) that provides a powerful environment for evaluating Groovy expressions, defining classes, and running experiments interactively. Built on JLine3, it offers rich cross-platform line editing capabilities with history, tab completion, ANSI color support, and a robust command system with online help and user alias support.

Package Information

  • Package Name: org.apache.groovy:groovy-groovysh
  • Package Type: Maven
  • Language: Groovy/Java
  • Installation: implementation 'org.apache.groovy:groovy-groovysh:5.0.0'

Core Imports

import org.apache.groovy.groovysh.jline.GroovyEngine
import org.apache.groovy.groovysh.Main

For programmatic usage:

import org.apache.groovy.groovysh.jline.GroovyEngine;
import org.apache.groovy.groovysh.jline.GroovyConsoleEngine;
import org.apache.groovy.groovysh.jline.GroovySystemRegistry;

Basic Usage

Command Line Usage

# Start interactive shell
groovysh

# Execute code and exit
groovysh --evaluate "println 'Hello World'"

# Load script file
groovysh --evaluate "load 'script.groovy'"

Programmatic Usage

import org.apache.groovy.groovysh.jline.GroovyEngine

// Create and configure engine
GroovyEngine engine = new GroovyEngine()

// Execute Groovy code
Object result = engine.execute("2 + 2")
println result // 4

// Manage variables
engine.put("name", "World")
Object greeting = engine.execute("'Hello, ' + name")
println greeting // "Hello, World"

// Check and retrieve variables
if (engine.hasVariable("name")) {
    Object value = engine.get("name")
    println "Name: $value"
}

Architecture

Groovysh is built around several key components:

  • Main Entry Point: Main class provides command-line interface with comprehensive option parsing
  • Script Engine: GroovyEngine handles code execution, variable management, and state persistence
  • Console System: GroovyConsoleEngine and GroovySystemRegistry manage REPL interaction and command processing
  • Command Registry: Built-in commands for file operations, debugging, documentation, and dependency management
  • JLine Integration: Rich terminal support with auto-completion, syntax highlighting, and history
  • Utility System: Helper classes for documentation lookup, object inspection, and class management

Capabilities

Script Execution Engine

Core engine for executing Groovy code programmatically, managing variables, imports, and providing code completion. Essential for embedding Groovy REPL functionality in applications.

class GroovyEngine {
    Object execute(String statement)
    Object execute(File script, Object[] args)
    Object execute(Object closure, Object... args)
    void put(String name, Object value)
    Object get(String name)
    boolean hasVariable(String name)
    Map<String, Object> find(String name)
    void reset()
}

Script Engine

Interactive Commands

Built-in shell commands for file operations, object inspection, documentation lookup, dependency management, and state control. These commands provide a rich interactive development environment.

// File operations
/load [options] [file]    // Load script file or saved state
/save [options] [file]    // Save current state or buffer
/slurp [options] file     // Parse structured data files

// Development tools  
/inspect [options] object // Inspect object properties and methods
/doc object              // Open documentation in browser
/grab coordinates        // Add Maven dependencies

// State management
/vars [name]             // Show or delete variables
/imports [name]          // Show or delete imports
/reset                   // Clear all state

Interactive Commands

Console Integration

Advanced console features including syntax highlighting, auto-completion, custom command registration, and integration with JLine3 terminal capabilities.

class GroovyConsoleEngine {
    void println(Map<String, Object> options, Object object)
}

class GroovySystemRegistry {
    Object execute(String line)
    boolean isCommandOrScript(String command)
}

Console Integration

Object Inspection and Documentation

Tools for exploring objects, browsing documentation, and understanding code structure during interactive development sessions.

class ObjectInspector {
    // Object introspection utilities
}

class DocFinder {
    // Documentation URL resolution
}

Documentation and Inspection

Types

// Core engine options
interface GroovyOptions {
    boolean CANONICAL_NAMES
    boolean NO_SYNTAX_CHECK  
    boolean RESTRICTED_COMPLETION
    boolean ALL_METHODS_COMPLETION
    boolean ALL_FIELDS_COMPLETION
    boolean ALL_CONSTRUCTORS_COMPLETION
    boolean IDENTIFIERS_COMPLETION
    boolean META_METHODS_COMPLETION
    boolean SYNTHETIC_METHODS_COMPLETION
}

// Data serialization formats
enum SerializationFormat {
    JSON, NONE
}

enum DeserializationFormat {
    JSON, GROOVY, NONE
}