This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch fix/split-cli-dependencies
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to refs/heads/fix/split-cli-dependencies by
this push:
new d6d49e85f3 Fix the command arguments example in the custom-commands
guide
d6d49e85f3 is described below
commit d6d49e85f38a99d53c06f9f611b4478d4c197d29
Author: James Daugherty <[email protected]>
AuthorDate: Sat Jul 18 12:16:06 2026 -0400
Fix the command arguments example in the custom-commands guide
The arguments/options example read `commandLine.args`: a command has no
`commandLine` property (the GrailsApplicationCommand trait exposes
`executionContext` and an `args` getter for the remaining arguments), and
`--`-prefixed flags are parsed as options rather than remaining arguments,
so
the example failed at runtime as written. Use the trait's `args` getter and
`executionContext.commandLine.hasOption(...)`, and correct the surrounding
prose to name `handle()` instead of `run()`.
---
grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc
b/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc
index 9f4577f2f2..43107b1547 100644
--- a/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc
+++ b/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc
@@ -126,7 +126,7 @@ class GreetCommand implements GrailsApplicationCommand {
}
----
-In this example, we've created a `GreetCommand` class that implements the
`GrailsApplicationCommand` trait. It provides a `getName()` method to define
the command name, a `getDescription()` method for a brief description, and the
`run()` method to specify the code to execute when the command is run.
+In this example, we've created a `GreetCommand` class that implements the
`GrailsApplicationCommand` trait. It provides a `getName()` method to define
the command name (overriding the default derived from the class name), a
`getDescription()` method for a brief description, and the `handle()` method to
specify the code to execute when the command is run.
Step 2: Build Your Grails Application
@@ -179,9 +179,10 @@ class GreetCommand implements GrailsApplicationCommand {
}
boolean handle() {
- def args = commandLine.args
- String name = args.size() > 0 ? args[0] : "user"
- boolean loud = args.contains("--loud")
+ // `args` (from the GrailsApplicationCommand trait) holds the
remaining arguments
+ // after the command name; `--`-prefixed flags are parsed as options
instead
+ String name = args ? args[0] : "user"
+ boolean loud = executionContext.commandLine.hasOption("loud")
if (loud) {
println("HELLO, $name! (LOUD)")