@@ -13,6 +13,8 @@ import scala.build._
13
13
import scala .build .blooprifle .BloopRifleConfig
14
14
import scala .build .compiler .{BloopCompilerMaker , ScalaCompilerMaker , SimpleScalaCompilerMaker }
15
15
import scala .build .errors .BuildException
16
+ import scala .build .interactive .Interactive
17
+ import scala .build .interactive .Interactive .{InteractiveAsk , InteractiveNop }
16
18
import scala .build .internal .CsLoggerUtil ._
17
19
import scala .build .internal .{Constants , FetchExternalBinary , OsLibc , Util }
18
20
import scala .build .options .{Platform , ScalacOpt , ShadowingSeq }
@@ -25,7 +27,7 @@ import scala.concurrent.duration._
25
27
import scala .util .Properties
26
28
import scala .util .control .NonFatal
27
29
28
- object SharedOptionsUtil {
30
+ object SharedOptionsUtil extends CommandHelpers {
29
31
30
32
private def downloadInputs (cache : FileCache [Task ]): String => Either [String , Array [Byte ]] = {
31
33
url =>
@@ -213,22 +215,56 @@ object SharedOptionsUtil {
213
215
localRepository = LocalRepo .localRepo(directories.directories.localRepoDir),
214
216
verbosity = Some (logging.verbosity),
215
217
strictBloopJsonCheck = strictBloopJsonCheck,
216
- interactive = Some (interactiveMode )
218
+ interactive = Some (() => interactive )
217
219
),
218
220
notForBloopOptions = bo.PostBuildOptions (
219
221
scalaJsLinkerOptions = linkerOptions(js)
220
222
)
221
223
)
222
224
}
223
225
224
- def interactiveMode : Boolean = logging.verbosityOptions.interactive
225
- .orElse(configDb.get(Keys .interactive).getOrElse(None ))
226
- .getOrElse(false )
226
+ def globalInteractiveWasSuggested : Option [Boolean ] =
227
+ configDb.getOrNone(Keys .globalInteractiveWasSuggested, logger)
227
228
228
- def configDb : ConfigDb =
229
- ConfigDb .open(v) match
230
- case Left (ex) => logger.exit(ex)
231
- case Right (configDb) => configDb
229
+ def interactive : Interactive =
230
+ (
231
+ logging.verbosityOptions.interactive,
232
+ configDb.getOrNone(Keys .interactive, logger),
233
+ globalInteractiveWasSuggested
234
+ ) match {
235
+ case (Some (true ), _, Some (true )) => InteractiveAsk
236
+ case (_, Some (true ), _) => InteractiveAsk
237
+ case (Some (true ), _, _) =>
238
+ val answers @ List (yesAnswer, _) = List (" Yes" , " No" )
239
+ InteractiveAsk .chooseOne(
240
+ """ You have run the current scala-cli command with the --interactive mode turned on.
241
+ |Would you like to leave it on permanently?""" .stripMargin,
242
+ answers
243
+ ) match {
244
+ case Some (answer) if answer == yesAnswer =>
245
+ configDb
246
+ .set(Keys .interactive, true )
247
+ .set(Keys .globalInteractiveWasSuggested, true )
248
+ .save(v.directories.directories)
249
+ logger.message(
250
+ " --interactive is now set permanently. All future scala-cli commands will run with the flag set to true."
251
+ )
252
+ logger.message(
253
+ " If you want to turn this setting off at any point, just run `scala-cli config interactive false`."
254
+ )
255
+ case _ =>
256
+ configDb
257
+ .set(Keys .globalInteractiveWasSuggested, true )
258
+ .save(v.directories.directories)
259
+ logger.message(
260
+ " If you want to turn this setting permanently on at any point, just run `scala-cli config interactive true`."
261
+ )
262
+ }
263
+ InteractiveAsk
264
+ case _ => InteractiveNop
265
+ }
266
+
267
+ def configDb : ConfigDb = ConfigDb .open(v).orExit(logger)
232
268
233
269
def downloadJvm (jvmId : String , options : bo.BuildOptions ): String = {
234
270
implicit val ec = options.finalCache.ec
0 commit comments