Skip to content

Commit 1f1b357

Browse files
committed
Add console interface for sbt
1 parent 01463f7 commit 1f1b357

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* sbt -- Simple Build Tool
2+
* Copyright 2008, 2009 Mark Harrah
3+
*/
4+
package xsbt
5+
6+
import xsbti.Logger
7+
import scala.tools.nsc.{ GenericRunnerCommand, Interpreter, InterpreterLoop, ObjectRunner, Settings }
8+
import scala.tools.nsc.interpreter.InteractiveReader
9+
import scala.tools.nsc.reporters.Reporter
10+
import scala.tools.nsc.util.ClassPath
11+
12+
import dotty.tools.dotc.repl.REPL
13+
import dotty.tools.dotc.repl.REPL.Config
14+
15+
class ConsoleInterface {
16+
def commandArguments(
17+
args: Array[String],
18+
bootClasspathString: String,
19+
classpathString: String,
20+
log: Logger
21+
): Array[String] = args
22+
23+
def run(args: Array[String],
24+
bootClasspathString: String,
25+
classpathString: String,
26+
initialCommands: String,
27+
cleanupCommands: String,
28+
loader: ClassLoader,
29+
bindNames: Array[String],
30+
bindValues: Array[Any],
31+
log: Logger
32+
): Unit = {
33+
val completeArgs =
34+
args :+
35+
"-bootclasspath" :+ bootClasspathString :+
36+
"-classpath" :+ classpathString
37+
38+
println("Starting dotty interpreter...")
39+
val repl = ConsoleInterface.customRepl(
40+
initialCommands :: Nil,
41+
cleanupCommands :: Nil,
42+
bindNames zip bindValues
43+
)
44+
repl.process(completeArgs)
45+
}
46+
}
47+
48+
object ConsoleInterface {
49+
def customConfig(
50+
initCmds: List[String],
51+
cleanupCmds: List[String],
52+
boundVals: Array[(String, Any)]
53+
) = new Config {
54+
override val initialCommands: List[String] = initCmds
55+
override val cleanupCommands: List[String] = cleanupCmds
56+
override val boundValues: Array[(String, Any)] = boundVals
57+
}
58+
59+
def customRepl(cfg: Config): REPL = new REPL {
60+
override lazy val config = cfg
61+
}
62+
63+
def customRepl(
64+
initCmds: List[String],
65+
cleanupCmds: List[String],
66+
boundVals: Array[(String, Any)]
67+
): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals))
68+
}

0 commit comments

Comments
 (0)