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
The following commit(s) were added to refs/heads/master by this push: new 08a0ed8129 GROOVY-8162: Update Groovysh to JLine3 (allow state to be saved) 08a0ed8129 is described below commit 08a0ed81296f86fb0629816b5aadbbe18cf0d118 Author: Paul King <pa...@asert.com.au> AuthorDate: Mon Jul 21 17:42:38 2025 +1000 GROOVY-8162: Update Groovysh to JLine3 (allow state to be saved) --- .../apache/groovy/groovysh/jline/GroovyCommands.groovy | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy index 804e011827..65398b8bac 100644 --- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy +++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy @@ -20,6 +20,7 @@ package org.apache.groovy.groovysh.jline import groovy.console.ui.Console import groovy.console.ui.ObjectBrowser +import org.apache.groovy.groovysh.Main import org.jline.builtins.Completers import org.jline.builtins.Completers.OptDesc import org.jline.builtins.Completers.OptionCompleter @@ -175,8 +176,13 @@ class GroovyCommands extends JlineCommandRegistry implements CommandRegistry { } void save(CommandInput input) { - checkArgCount(input, [1, 2]) + checkArgCount(input, [0, 1, 2]) if (maybePrintHelp(input, '/save')) return + if (input.args().length == 0) { + def out = new File(Main.userStateDirectory, 'groovysh.ser') + out.text = engine.toJson(engine.sharedData) + return + } boolean overwrite = false String arg = input.args()[0] if (arg == '-o' || arg == '--overwrite') { @@ -198,8 +204,15 @@ class GroovyCommands extends JlineCommandRegistry implements CommandRegistry { } void load(CommandInput input) { - checkArgCount(input, [1, 2]) + checkArgCount(input, [0, 1, 2]) if (maybePrintHelp(input, '/load')) return + if (input.args().length == 0) { + def ser = new File(Main.userStateDirectory, 'groovysh.ser') + def map = engine.sharedData.variables + map.clear() + map.putAll(engine.deserialize(ser.text).variables) + return + } boolean merge = false String arg = input.args()[0] if (arg == '-m' || arg == '--merge') {