@@ -8,23 +8,26 @@ import dependency.AnyDependency
8
8
import dependency .parser .DependencyParser
9
9
10
10
import java .io .{File , InputStream }
11
-
12
- import scala .build ._
11
+ import scala .build .*
13
12
import scala .build .blooprifle .BloopRifleConfig
14
13
import scala .build .compiler .{BloopCompilerMaker , ScalaCompilerMaker , SimpleScalaCompilerMaker }
15
14
import scala .build .errors .BuildException
16
- import scala .build .internal .CsLoggerUtil ._
15
+ import scala .build .interactive .Interactive
16
+ import scala .build .interactive .Interactive .{InteractiveAsk , InteractiveNop }
17
+ import scala .build .internal .CsLoggerUtil .*
17
18
import scala .build .internal .{Constants , FetchExternalBinary , OsLibc , Util }
18
19
import scala .build .options .{Platform , ScalacOpt , ShadowingSeq }
19
- import scala .build .{ options => bo }
20
+ import scala .build .options as bo
20
21
import scala .cli .commands .ScalaJsOptions
21
- import scala .cli .commands .util .CommonOps ._
22
- import scala .cli .commands .util .SharedCompilationServerOptionsUtil ._
23
- import scala .concurrent .duration ._
22
+ import scala .cli .commands .util .CommonOps .*
23
+ import scala .cli .commands .util .SharedCompilationServerOptionsUtil .*
24
+ import scala .cli .config .{ConfigDb , Keys }
25
+ import scala .concurrent .ExecutionContextExecutorService
26
+ import scala .concurrent .duration .*
24
27
import scala .util .Properties
25
28
import scala .util .control .NonFatal
26
29
27
- object SharedOptionsUtil {
30
+ object SharedOptionsUtil extends CommandHelpers {
28
31
29
32
private def downloadInputs (cache : FileCache [Task ]): String => Either [String , Array [Byte ]] = {
30
33
url =>
@@ -62,7 +65,7 @@ object SharedOptionsUtil {
62
65
logger.message(s " WARNING: provided resource directory path doesn't exist: $path" )
63
66
path
64
67
}
65
- .map(Inputs .ResourceDirectory (_) )
68
+ .map(Inputs .ResourceDirectory )
66
69
val maybeInputs = Inputs (
67
70
args,
68
71
Os .pwd,
@@ -91,7 +94,7 @@ object SharedOptionsUtil {
91
94
implicit class SharedOptionsOps (v : SharedOptions ) {
92
95
import v ._
93
96
94
- def logger = logging.logger
97
+ def logger : Logger = logging.logger
95
98
96
99
private def scalaJsOptions (opts : ScalaJsOptions ): options.ScalaJsOptions = {
97
100
import opts ._
@@ -165,11 +168,11 @@ object SharedOptionsUtil {
165
168
scalac.scalacOption
166
169
.filter(_.nonEmpty)
167
170
.map(ScalacOpt (_))
168
- .map(Positioned .commandLine(_) )
171
+ .map(Positioned .commandLine)
169
172
),
170
173
compilerPlugins =
171
174
SharedOptionsUtil .parseDependencies(
172
- dependencies.compilerPlugin.map(Positioned .none(_) ),
175
+ dependencies.compilerPlugin.map(Positioned .none),
173
176
ignoreErrors
174
177
),
175
178
platform = platformOpt.map(o => Positioned (List (Position .CommandLine ()), o))
@@ -202,7 +205,7 @@ object SharedOptionsUtil {
202
205
extraRepositories = dependencies.repository.map(_.trim).filter(_.nonEmpty),
203
206
extraDependencies = ShadowingSeq .from(
204
207
SharedOptionsUtil .parseDependencies(
205
- dependencies.dependency.map(Positioned .none(_) ),
208
+ dependencies.dependency.map(Positioned .none),
206
209
ignoreErrors
207
210
)
208
211
)
@@ -212,16 +215,59 @@ object SharedOptionsUtil {
212
215
localRepository = LocalRepo .localRepo(directories.directories.localRepoDir),
213
216
verbosity = Some (logging.verbosity),
214
217
strictBloopJsonCheck = strictBloopJsonCheck,
215
- interactive = logging.verbosityOptions. interactive
218
+ interactive = Some (() => interactive)
216
219
),
217
220
notForBloopOptions = bo.PostBuildOptions (
218
221
scalaJsLinkerOptions = linkerOptions(js)
219
222
)
220
223
)
221
224
}
222
225
226
+ def globalInteractiveWasSuggested : Option [Boolean ] =
227
+ configDb.getOrNone(Keys .globalInteractiveWasSuggested, logger)
228
+
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)
268
+
223
269
def downloadJvm (jvmId : String , options : bo.BuildOptions ): String = {
224
- implicit val ec = options.finalCache.ec
270
+ implicit val ec : ExecutionContextExecutorService = options.finalCache.ec
225
271
val javaHomeManager = options.javaHomeManager
226
272
.withMessage(s " Downloading JVM $jvmId" )
227
273
val logger = javaHomeManager.cache
@@ -306,7 +352,7 @@ object SharedOptionsUtil {
306
352
! Properties .isWin
307
353
)
308
354
309
- def strictBloopJsonCheckOrDefault =
355
+ def strictBloopJsonCheckOrDefault : Boolean =
310
356
strictBloopJsonCheck.getOrElse(bo.InternalOptions .defaultStrictBloopJsonCheck)
311
357
}
312
358
0 commit comments