Play 2.0 “management” console commands

2019-05-08 10:46发布

问题:

I'd like to create some custom commands to manage my play 2.0 application (similar to Django's management commands), so I can run things like play import-data <data>.

This seems to be something one would do by writing SBT commands (like Play's own), but specific to the particular project and with access to a project's resources (models etc.)

Being fairly new to Scala, and new to both Play and SBT, I cannot get my head around how to do this, and particularly the dependency management that is involved. The SBT plugin documentation is very nice, but it seems to assume I want to create standalone, published plugins, rather than ones that depend on the main project.

Does anyone know of a walkthrough for something similar, or have any specific suggestions for how "management commands" could otherwise be implemented?

回答1:

To begin, you could take a look at the existing Play's sbt-plugins: https://github.com/playframework/Play20/tree/master/framework/src/sbt-plugin/src/main/scala