This is a simple-build-tool plugin that lets you declare and edit Scala classes, traits and objects from the sbt command line, and automatically load them into your favourite editor. This is useful if you are spending a lot of time on the command line.
Put this in a .scala file in your $PROJECT_BASE/project/project directory:
import sbt._
object PluginDef extends Build {
override def projects = Seq(root dependsOn createAndEditPlugin)
def root = Project("plugins", file("."))
def createAndEditPlugin = uri("git://github.com/kenbot/CreateAndEditPlugin.git")
}
At the sbt prompt, declare classes, traits or objects:
> class com.grocery.Potato
Created C:\Ken\Projects\SimpleGame\src\main\scala\com\grocery\Potato.scala
> trait com.grocery.Blah
Created C:\Ken\Projects\SimpleGame\src\main\scala\com\grocery\Blah.scala
> object com.stuff.Gumball
Created C:\Ken\Projects\SimpleGame\src\main\scala\com\stuff\Gumball.scala
You can change the generated source file template:
createAndEditConfig ~= (_ usingSourceTemplate "package %s\n import usefulimports\n %s %s {\n}")
If you define create-and-edit-config with a test file template in your build.sbt:
createAndEditConfig ~= (_ usingTestTemplate "package %s; class %sTest {}")
then test files will be created as well:
> trait com.grocery.Potato
Created C:\Ken\Projects\SimpleGame\src\main\scala\com\grocery\Potato.scala
Created C:\Ken\Projects\SimpleGame\src\test\scala\com\grocery\PotatoSpec.scala
You can also configure the test file name pattern:
createAndEditConfig ~= (_ usingTestFileName "%s/%sTest.scala")
If you choose an editor command:
createAndEditConfig ~= (_ editWith "~/bin/eclipse")
then the class/trait/object commands will also launch the newly created file in an editor.
The edit command will edit files directly:
> edit com.grocery.Potato
Executing ~/bin/eclipse /usr/apps/myproject/src/main/scala/com/grocery/Potato.scala