Skip to content

Commit

Permalink
Add REPL setting to quit after evaluating init script
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Feb 21, 2025
1 parent 28fa050 commit c18ac07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ trait CommonScalaSettings:
val usejavacp: Setting[Boolean] = BooleanSetting(RootSetting, "usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
val scalajs: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
val replInitScript: Setting[String] = StringSetting(RootSetting, "repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script"))
val replEvalOnly: Setting[Boolean] = BooleanSetting(RootSetting, "repl-eval", "Quit REPL after evaluating the init script.", aliases = List("--repl-eval"))
end CommonScalaSettings

/** -P "plugin" settings. Various tools might support plugins. */
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ class ReplDriver(settings: Array[String],
*
* Possible reason for unsuccessful run are raised flags in CLI like --help or --version
*/
final def tryRunning = if shouldStart then runUntilQuit()
final def tryRunning = if shouldStart then
if rootCtx.settings.replEvalOnly.value(using rootCtx) then initialState
else runUntilQuit()

/** Run REPL with `state` until `:quit` command found
*
Expand Down

0 comments on commit c18ac07

Please sign in to comment.