This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit d81b3666d58db6e701b1b6f82df3912c66bf79c4
Author: Paul King <[email protected]>
AuthorDate: Wed Aug 6 16:13:04 2025 +1000

    GROOVY-8162: Update Groovysh to JLine3 (fancy banner and begin reworking 
CLI options)
---
 .../groovy/org/apache/groovy/groovysh/Main.groovy  | 46 ++++++++++++++++++++--
 .../org/apache/groovy/groovysh/Main.properties     | 38 ++++++++++++++++++
 2 files changed, 81 insertions(+), 3 deletions(-)

diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
index 3cd18104fc..c81ed32ba5 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
@@ -18,6 +18,8 @@
  */
 package org.apache.groovy.groovysh
 
+import groovy.cli.internal.CliBuilderInternal
+import groovy.cli.internal.OptionAccessor
 import org.apache.groovy.groovysh.jline.GroovyBuiltins
 import org.apache.groovy.groovysh.jline.GroovyCommands
 import org.apache.groovy.groovysh.jline.GroovyConsoleEngine
@@ -180,6 +182,39 @@ class Main {
     }
 
     static void main(String[] args) {
+        def cli = new CliBuilderInternal(usage: 'groovysh [options] [...]', 
stopAtNonOption: false,
+            header: messages['cli.option.header'])
+        cli.with {
+            _(names: ['-cp', '-classpath', '--classpath'], 
messages['cli.option.classpath.description'])
+            h(longOpt: 'help', messages['cli.option.help.description'])
+            V(longOpt: 'version', messages['cli.option.version.description'])
+            v(longOpt: 'verbose', messages['cli.option.verbose.description'])
+            q(longOpt: 'quiet', messages['cli.option.quiet.description'])
+            d(longOpt: 'debug', messages['cli.option.debug.description'])
+            e(longOpt: 'evaluate', args: 1, argName: 'CODE', optionalArg: 
false, messages['cli.option.evaluate.description'])
+            C(longOpt: 'color', args: 1, argName: 'FLAG', optionalArg: true, 
messages['cli.option.color.description'])
+            D(longOpt: 'define', type: Map, argName: 'name=value', 
messages['cli.option.define.description'])
+            T(longOpt: 'terminal', args: 1, argName: 'TYPE', 
messages['cli.option.terminal.description'])
+            pa(longOpt: 'parameters', 
messages['cli.option.parameters.description'])
+            pr(longOpt: 'enable-preview', 
messages['cli.option.enable.preview.description'])
+        }
+        OptionAccessor options = cli.parse(args)
+
+        if (options == null) {
+            // CliBuilder prints error, but does not exit
+            System.exit(22) // Invalid Args
+        }
+
+        if (options.h) {
+            cli.usage()
+            System.exit(0)
+        }
+
+        if (options.V) {
+            println render(messages.format('cli.info.version', 
GroovySystem.version))
+            System.exit(0)
+        }
+
         try {
             Supplier<Path> workDir = () -> 
Paths.get(System.getProperty('user.dir'))
             DefaultParser parser = new DefaultParser(
@@ -284,11 +319,16 @@ class Main {
             keyMap.bind(new Reference(Widgets.AUTOSUGGEST_TOGGLE), 
KeyMap.alt("v"))
             def init = configPath.getUserConfig('groovysh_init')
             if (init) {
-                
systemRegistry.initialize(configPath.getUserConfig('groovysh_init').toFile())
+                systemRegistry.setConsoleOption() // 
initialize(configPath.getUserConfig('groovysh_init').toFile())
             }
 
-            println render(messages.format('startup_banner.0', 
GroovySystem.version, System.properties['java.version'], terminal.type))
-            println render(messages['startup_banner.1'])
+            if (options.q) {
+                println render(messages.format('cli.info.version', 
GroovySystem.version))
+            } else {
+                println render(messages.format('startup_banner.0', 
GroovySystem.version, System.properties['java.version'], terminal.type))
+                println render(messages['startup_banner.1'])
+                println render(messages['startup_banner.2'])
+            }
             println '-' * (terminal.width - 1)
 // for debugging
 //            def index = 0
diff --git 
a/subprojects/groovy-groovysh/src/main/resources/org/apache/groovy/groovysh/Main.properties
 
b/subprojects/groovy-groovysh/src/main/resources/org/apache/groovy/groovysh/Main.properties
index c59810cb2a..1087a4f627 100644
--- 
a/subprojects/groovy-groovysh/src/main/resources/org/apache/groovy/groovysh/Main.properties
+++ 
b/subprojects/groovy-groovysh/src/main/resources/org/apache/groovy/groovysh/Main.properties
@@ -20,3 +20,41 @@
 startup_banner.0=@|green Groovy Shell|@ ({0}, JVM: {1}, Term: {2})
 
 startup_banner.1=Type '@|bold /help|@' or '@|bold /h|@' for help, '@|bold 
/exit|@' or '@|bold /x|@' to exit.
+
+startup_banner.2=\
+@|red        |@@|yellow      |@@|green            |@@|cyan      |@@|blue      
|@@|magenta      _      |@\n\
+@|red   __ _ |@@|yellow _ __ |@@|green ___   ___|@@|cyan __   __|@@|blue _   
_|@@|magenta  ___| |__   |@\n\
+@|red  / _` ||@@|yellow  '__/|@@|green  _ \\ / _ \\|@@|cyan  \\ / /|@@|blue  | 
| |@@|magenta / __| '_ \\  |@\n\
+@|red | (_| ||@@|yellow  | |@@|green | (_) | (_) \\|@@|cyan  V /|@@|blue | |_| 
|@@|magenta \\__ \\ | | | |@\n\
+@|red  \\__, ||@@|yellow _| |@@|green  \\___/ \\___/ |@@|cyan \\_/ |@@|blue  
\\__, |@@|magenta |___/_| |_| |@\n\
+@|red  |___/ |@@|yellow    |@@|green               |@@|cyan    |@@|blue  |___/ 
|@
+
+cli.option.header=The Groovy Shell, aka groovysh, is a command-line 
application which allows easy access to evaluate Groovy expressions, define 
classes and run simple experiments.
+
+cli.option.help.description=Display this help message
+
+cli.option.version.description=Display the version
+
+cli.option.verbose.description=Enable verbose output
+
+cli.option.quiet.description=Suppress superfluous output
+
+cli.option.debug.description=Enable debug output
+
+cli.option.evaluate.description=Evaluate the code first when starting 
interactive session
+
+cli.option.cp.description=Aliases for '-classpath'
+
+cli.option.classpath.description=Specify where to find the class files - must 
be first argument
+
+cli.option.color.description=Enable or disable use of ANSI colors
+
+cli.option.define.description=Define a system property
+
+cli.option.terminal.description=Specify the terminal TYPE to use
+
+cli.option.enable.preview.description=Enable preview Java features (jdk12+ 
only) - must be after classpath but before other arguments
+
+cli.option.parameters.description=Generate metadata for reflection on method 
parameter names (jdk8+ only)
+
+cli.info.version=@|red g|@@|yellow r|@@|green oo|@@|cyan v|@@|blue 
y|@@|magenta sh|@ {0}

Reply via email to