Ghata.Shah
Ghata.Shah

Reputation: 11

How to create custom commands in Grails 3?

I need to create custom command in Grails 3 which I can then execute from command line as we can generate default commands such as run-app. I am not sure whether to create script or anything else to achieve this.

Upvotes: 1

Views: 612

Answers (2)

npskirk
npskirk

Reputation: 1188

The instructions seem to work

[0] % grails create-app script-test
| Application created at /Users/kirk/tmp/script-test

[0] % cd script-test

[0] % grails create-script my-script

BUILD SUCCESSFUL

| Rendered template Script.groovy to destination src/main/scripts/my-script.groovy

[0] % cat src/main/scripts/my-script.groovy
description "Example description", "grails example-usage"

println "Example Script"%

[0] % grails my-script
Example Script

[0] % grails
| Enter a command name to run. Use TAB for completion:
grails> my-script
Example Script

Tab completion works also.

However, if you create the script with an interactive shell running, that shell won't see the script until you restart the shell.

[0] % grails
| Enter a command name to run. Use TAB for completion:
grails> create-script wibble
| Rendered template Script.groovy to destination src/main/scripts/wibble.groovy
grails> wibble
| Error Command not found wibble
Did you mean: assemble or clean or gradle?
grails> % quit
[0] % grails wibble
Example Script
grails> wibble
Example Script
grails>

Upvotes: 1

Gregg
Gregg

Reputation: 35864

Documentation to the rescue! Here is how to do what you are asking.

Upvotes: 0

Related Questions