Skip to content

Commit 38745fd

Browse files
authored
Merge pull request #272 from scala/backport-lts-3.3-22636
Backport "Fix scala#21242: Add REPL flag to quit after evaluating init script" to 3.3 LTS
2 parents da6d314 + ee6ea24 commit 38745fd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

bin/replQ

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
4+
. $ROOT/bin/commonQ
5+
6+
java -Dscala.usejavacp=true -cp $cp dotty.tools.repl.Main -usejavacp "$@"

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

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ trait CommonScalaSettings:
135135
val usejavacp: Setting[Boolean] = BooleanSetting("-usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
136136
val scalajs: Setting[Boolean] = BooleanSetting("-scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
137137
val replInitScript: Setting[String] = StringSetting("-repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script"))
138+
val replQuitAfterInit: Setting[Boolean] = BooleanSetting("-repl-quit-after-init", "Quit REPL after evaluating the init script.", aliases = List("--repl-quit-after-init"))
138139

139140
end CommonScalaSettings
140141

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ class ReplDriver(settings: Array[String],
139139
*
140140
* Possible reason for unsuccessful run are raised flags in CLI like --help or --version
141141
*/
142-
final def tryRunning = if shouldStart then runUntilQuit()
142+
final def tryRunning = if shouldStart then
143+
if rootCtx.settings.replQuitAfterInit.value(using rootCtx) then initialState
144+
else runUntilQuit()
143145

144146
/** Run REPL with `state` until `:quit` command found
145147
*

0 commit comments

Comments
 (0)