Skip to content

@khronnuz /ShellSupport.scala
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to create DSL in Scala for command lines with minimum boilerplate
package lib
import sys.process.{Process, stringToProcess}
class Shell {
var elems = Vector[String]()
var cwd = "/tmp"
def >(str: String) = elems :+= str
def run() = elems.map( cmd => {
val CdPattern = "cd (.*)".r
cmd match {
case CdPattern(dir) =>
cwd = dir
"directory changed to " + dir
case anyCmd => Process(anyCmd,new java.io.File(cwd))!!
}
}
)
}
trait ShellSupport extends DelayedInit{
var result = Vector[String]()
val $ = new Shell()
def delayedInit(x: => Unit) {
x
result = $.run()
}
}
package scripting
import lib.ShellSupport
class Turismo extends ShellSupport {
$> "rm -rf /tmp/scripting"
$> "mkdir /tmp/scripting"
$> "cd /tmp/scripting"
$> "mkdir oops"
}
Something went wrong with that request. Please try again.