package scala.tools
package cmd
trait Interpolation {
self: Spec =>
private lazy val reference = referenceSpec
import reference._
object interpolate {
def mapper: Map[String, () => String] = Map(
"PROGRAM" -> (() => programInfo.runner),
"ALLOPTIONS" -> (() => options.all mkString " "),
"MAINCLASS" -> (() => programInfo.mainClass)
)
private def mark(key: String) = "@@" + key + "@@"
def apply(template: String) = mapper.foldLeft(template) { case (s, (key, f)) => s.replaceAll(mark(key), f()) }
}
}
object Interpolation {
lazy val bashTemplate = """
|_@@PROGRAM@@()
|{
| local cur opts base
| COMPREPLY=()
| cur="${COMP_WORDS[COMP_CWORD]}"
| opts="@@ALLOPTIONS@@"
|
| COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
| _filedir
| return 0
|} && complete -F _@@PROGRAM@@ @@PROGRAM@@
""".stripMargin
val runnerTemplate = """
|#!/bin/sh
|#
|
|scala @@MAINCLASS@@ "$@"
|""".stripMargin.trim + "\n"
}
<iframe src="https://xuwei-k.github.io/scala-compiler-sxr/scala-compiler-2.9.1/scala/tools/cmd/Interpolation.scala.html" width="1280" height="720" frameborder="0"> </iframe>