Reputation: 2211
I want to create grails script which adds an admin account to my application. Something like:
grails run-script utils/adminAdd.groovy username password
Unfortunately, it seems like run-script doesn't support passing arguments to scripts (allowing one to run multiple scripts at once, instead). Anyone knows a workaround?
Upvotes: 6
Views: 2005
Reputation: 63
If anyone is still looking for a ready solution, here it is.
I solved this issue by digging into the grails-2.x/scripts/RunScript.groovy. Then I made myself a new script called RunSingleScript.groovy, which accepts arguments, instead of the original list of scripts.
I believe this code could be re-written to something like what Burt suggested, and make it part of the core RunScript.groovy. I am lazy, and kind of busy, so I made a custom script which does the job.
Upvotes: 0
Reputation: 7054
See my answer to How can I run a Groovy class from the command-line within a Grails environment?
In short, you need includeTargets << grailsScript("_GrailsArgParsing")
in your script; see documentation for more options.
Upvotes: 0
Reputation: 75681
This should be supported, so you should create an issue at http://jira.grails.org/browse/GRAILS
In the meantime I think to keep backwards compatibility you probably need a way to differentiate script names from args, e.g. a prefix:
grails run-script utils/adminAdd.groovy -Jusername -Jpassword -Jfoo=bar
Then run-script
could split out the args list into un-prefixed script names and send the de-prefixed args to each script as it runs.
Once you get it working locally send a pull request or attach the updated script to the JIRA and it'll get fixed a lot quicker.
Upvotes: 4