Skip to content

Commit c18ac07

Browse files
committed
Add REPL setting to quit after evaluating init script
1 parent 28fa050 commit c18ac07

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ trait CommonScalaSettings:
127127
val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
128128
val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
129129
val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script"))
130+
val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-eval", "Quit REPL after evaluating the init script.", aliases = List("--repl-eval"))
130131
end CommonScalaSettings
131132

132133
/** -P "plugin" settings. Various tools might support plugins. */

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ class ReplDriver(settings: Array[String],
153153
*
154154
* Possible reason for unsuccessful run are raised flags in CLI like --help or --version
155155
*/
156-
final def tryRunning = if shouldStart then runUntilQuit()
156+
final def tryRunning = if shouldStart then
157+
if rootCtx.settings.replEvalOnly.value(using rootCtx) then initialState
158+
else runUntilQuit()
157159

158160
/** Run REPL with `state` until `:quit` command found
159161
*

0 commit comments

Comments
 (0)