Skip to content

Commit

Permalink
Fix for GRAILS-9035. 'grails -help' and 'grails -help foo' now shows …
Browse files Browse the repository at this point in the history
…a deprecation message with instructions to use 'grails help' or 'grails help foo'.

'grails help' now shows the list of options as 'grails -help' previously did, in addition to the list of targets.
  • Loading branch information
rlovtangen committed Apr 22, 2012
1 parent 0f2c77b commit f8d6b99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ public static void main(String[] args) {
} }


if (commandLine.hasOption(CommandLine.HELP_ARGUMENT)) { if (commandLine.hasOption(CommandLine.HELP_ARGUMENT)) {
console.log(parser.getHelpMessage()); if (commandLine.getCommandName() != null) {
console.log("The '-help' option is deprecated; use 'grails help [target]'");
} else {
console.log("The '-help' option is deprecated; use 'grails help'");
}
System.exit(0); System.exit(0);
} }


Expand Down Expand Up @@ -247,7 +251,6 @@ public static CommandLineParser getCommandLineParser() {
parser.addOption(CommandLine.STACKTRACE_ARGUMENT, "Enable stack traces in output"); parser.addOption(CommandLine.STACKTRACE_ARGUMENT, "Enable stack traces in output");
parser.addOption(CommandLine.AGENT_ARGUMENT, "Enable the reloading agent"); parser.addOption(CommandLine.AGENT_ARGUMENT, "Enable the reloading agent");
parser.addOption(CommandLine.NON_INTERACTIVE_ARGUMENT, "Whether to allow the command line to request input"); parser.addOption(CommandLine.NON_INTERACTIVE_ARGUMENT, "Whether to allow the command line to request input");
parser.addOption(CommandLine.HELP_ARGUMENT, "Command line help");
parser.addOption(CommandLine.VERSION_ARGUMENT, "Current Grails version"); parser.addOption(CommandLine.VERSION_ARGUMENT, "Current Grails version");
parser.addOption(CommandLine.NOANSI_ARGUMENT, "Disables ANSI output"); parser.addOption(CommandLine.NOANSI_ARGUMENT, "Disables ANSI output");
return parser; return parser;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ private void parseInternal(DefaultCommandLine cl, String[] args, boolean firstAr
} }
} }


public String getHelpMessage() { public String getOptionsHelpMessage() {
String ls = System.getProperty("line.separator"); String ls = System.getProperty("line.separator");
usageMessage = "usage: grails [options] [command]"; usageMessage = "Available options:";
StringBuilder sb = new StringBuilder(usageMessage); StringBuilder sb = new StringBuilder(usageMessage);
sb.append(ls); sb.append(ls);
for (Option option : declaredOptions.values()) { for (Option option : declaredOptions.values()) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CommandLineParserSpec extends Specification {


then: then:
String ls = System.getProperty("line.separator"); String ls = System.getProperty("line.separator");
parser.helpMessage == "usage: grails [options] [command]${ls} -interactive-mode Enabled interactive mode${ls} -version Shows the vesrion${ls}" parser.optionsHelpMessage == "Available options:${ls} -interactive-mode Enabled interactive mode${ls} -version Shows the vesrion${ls}"
} }


// STRING tests // STRING tests
Expand Down
6 changes: 5 additions & 1 deletion scripts/Help_.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


import grails.util.GrailsNameUtils import grails.util.GrailsNameUtils
import grails.util.Environment import grails.util.Environment
import org.codehaus.groovy.grails.cli.GrailsScriptRunner


includeTargets << grailsScript("_GrailsInit") includeTargets << grailsScript("_GrailsInit")


Expand Down Expand Up @@ -76,12 +77,15 @@ target ('default' : "Prints out the help for each script") {
else { else {
println """ println """
Usage (optionals marked with *): Usage (optionals marked with *):
grails [environment]* [target] [arguments]* grails [environment]* [options]* [target] [arguments]*
Examples: Examples:
grails dev run-app grails dev run-app
grails create-app books grails create-app books
"""
println GrailsScriptRunner.commandLineParser.optionsHelpMessage
println """
Available Targets (type grails help 'target-name' for more info):""" Available Targets (type grails help 'target-name' for more info):"""


scripts.unique { it.name }. sort{ it.name }.each { file -> scripts.unique { it.name }. sort{ it.name }.each { file ->
Expand Down

0 comments on commit f8d6b99

Please sign in to comment.