Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hitting [ENTER] on the CLI with no text entered reruns the last successful script #138

Closed
wants to merge 2 commits into from

4 participants

@henyojess

Hitting [ENTER] on the CLI with no text entered reruns the last successful script

The above is the previous behaviour on grails 1.3.7.

It saves keystrokes especially when the last script run is something like: test-app -unit

.../groovy/grails/cli/interactive/InteractiveMode.groovy
@@ -97,6 +97,9 @@ class InteractiveMode {
addStatus("Enter a script name to run. Use TAB for completion: ")
while (interactiveModeActive) {
def scriptName = showPrompt()
+ if(!scriptName.trim() && lastScriptName){
+ scriptName = lastScriptName
+ }
try {
def trimmed = scriptName.trim()
@antony
antony added a note

You're trimming the script name twice here which is unnecessary. Perhaps set a variable above this statement called 'trimmed' and remove line 104?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@henyojess

thanks for the comment. made some adjustments to remove unnecessary trim() call

@marcoVermeulen

Is this really the behaviour we would expect from an interactive shell?
Usually when you hit return in any shell, it simply opens a new line...

@antony

That's the behaviour I would expect too Marco.
Perhaps a bash-like "!" syntax should repeat the last command.

@marcoVermeulen

Yep, letting "!" repeat the last command entered (successful or not) sounds sensible to me too.

@henyojess

This is one keystroke too many if you ask me. It's no different from hitting the [UP] key to bring up the previous command then hitting [ENTER]

@antony
@marcoVermeulen

Don't know if you both spend a lot of time on the command line, but no console that I'm aware of has this behaviour.
Hitting enter always opens a new line on a shell. Be it bash, ksh, dos, groovysh or even the roo shell.

It might be argued what the command to repeat should be (we've gone for !), but I still don't think that simply hitting enter to repeat is a sensible default. Bash uses !!, which is probably the better option.

@antony
@henyojess

Enter to repeat last command was how grails interactive behaved with the previous versions i.e. 1.3.7, 1.2.5

Maybe this behavior could be an option for those who want it? Where does one put grails configuration stuff?

@lhotari
Owner

Closing outdated pull requests.

@lhotari lhotari closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2011
  1. hitting enter on the CLI (i.e. no text entered) reruns last successfu…

    Jessie Evangelista authored
    …l command
Commits on Dec 20, 2011
  1. cleaned up unnecessary trim() call as pointed out by aiten

    Jessie Evangelista authored
This page is out of date. Refresh to see the latest.
View
7 grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/interactive/InteractiveMode.groovy
@@ -81,7 +81,7 @@ class InteractiveMode {
static boolean isActive() {
getCurrent() != null && getCurrent().interactiveModeActive
}
-
+ def lastScriptName = null
void run() {
current = this
System.setProperty("grails.disable.exit", "true") // you can't exit completely in interactive mode from a script
@@ -99,6 +99,10 @@ class InteractiveMode {
def scriptName = showPrompt()
try {
def trimmed = scriptName.trim()
+ if(!trimmed && lastScriptName){
+ trimmed = lastScriptName
+ scriptName = lastScriptName
+ }
if (trimmed) {
if(trimmed.startsWith("create-app")) {
error "You cannot create an application in interactive mode."
@@ -168,6 +172,7 @@ class InteractiveMode {
console.stacktrace = commandLine.hasOption(CommandLine.STACKTRACE_ARGUMENT)
console.verbose = commandLine.hasOption(CommandLine.VERBOSE_ARGUMENT)
scriptRunner.executeScriptWithCaching(commandLine)
+ lastScriptName = scriptName.trim()
} catch (ParseException e) {
error "Invalid command: ${e.message}"
}
Something went wrong with that request. Please try again.