Skip to content

Commit

Permalink
Suggest global interactive mode the first time --interactive is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Aug 4, 2022
1 parent 3315c66 commit 342c073
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import scala.build._
import scala.build.blooprifle.BloopRifleConfig
import scala.build.compiler.{BloopCompilerMaker, ScalaCompilerMaker, SimpleScalaCompilerMaker}
import scala.build.errors.BuildException
import scala.build.interactive.Interactive
import scala.build.interactive.Interactive.{InteractiveAsk, InteractiveNop}
import scala.build.internal.CsLoggerUtil._
import scala.build.internal.{Constants, FetchExternalBinary, OsLibc, Util}
import scala.build.options.{Platform, ScalacOpt, ShadowingSeq}
Expand Down Expand Up @@ -213,17 +215,53 @@ object SharedOptionsUtil {
localRepository = LocalRepo.localRepo(directories.directories.localRepoDir),
verbosity = Some(logging.verbosity),
strictBloopJsonCheck = strictBloopJsonCheck,
interactive = Some(interactiveMode)
interactive = Some(() => interactive)
),
notForBloopOptions = bo.PostBuildOptions(
scalaJsLinkerOptions = linkerOptions(js)
)
)
}

def interactiveMode: Boolean = logging.verbosityOptions.interactive
.orElse(configDb.get(Keys.interactive).getOrElse(None))
.getOrElse(false)
def globalInteractiveWasSuggested: Option[Boolean] =
configDb.get(Keys.globalInteractiveWasSuggested).getOrElse(None)

def interactive: Interactive = logging.verbosityOptions.interactive
.orElse(
configDb.get(Keys.interactive).getOrElse(None)
) -> globalInteractiveWasSuggested match {
case (Some(true), Some(true)) => InteractiveAsk
case (Some(true), _) =>
val answers @ List(yesAnswer, _) = List("Yes", "No")
InteractiveAsk.chooseOne(
"""You have run the current scala-cli command with the --interactive mode turned on.
|Would you like to leave it on permanently?""".stripMargin,
answers
) match {
case a @ Some(answer) if answer == yesAnswer =>
configDb
.set(Keys.interactive, true)
.set(Keys.globalInteractiveWasSuggested, true)
.save(v.directories.directories)
logger.log(
"--interactive is now set permanently. All future scala-cli commands will run with the flag set to true."
)
logger.log(
"If you want to turn this setting off at any point, just run `scala-cli config interactive false`."
)
println(a)
case a @ _ =>
configDb
.set(Keys.globalInteractiveWasSuggested, true)
.save(v.directories.directories)
logger.log(
"If you want to turn this setting permanently on at any point, just run `scala-cli config interactive true`."
)
println(a)
}
InteractiveAsk
case _ => InteractiveNop
}

def configDb: ConfigDb =
ConfigDb.open(v) match
Expand Down
4 changes: 4 additions & 0 deletions modules/cli/src/main/scala/scala/cli/config/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ object Keys {

val interactive = new Key.BooleanEntry(Seq.empty, "interactive")

// setting indicating if the global interactive mode was suggested
val globalInteractiveWasSuggested = new Key.BooleanEntry(Seq.empty, "interactive-was-suggested")

def all = Seq[Key[_]](
interactive,
globalInteractiveWasSuggested,
actions,
userName,
userEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,7 @@ final case class BuildOptions(
}
}

val interactive: Interactive =
if (internal.interactive.getOrElse(false)) InteractiveAsk else InteractiveNop
lazy val interactive: Interactive = internal.interactive.getOrElse(() => InteractiveNop)()
}

object BuildOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import coursier.cache.FileCache
import coursier.util.Task

import scala.build.Positioned
import scala.build.interactive.Interactive
import scala.build.interactive.Interactive.InteractiveNop

final case class InternalOptions(
keepDiagnostics: Boolean = false,
Expand All @@ -12,7 +14,7 @@ final case class InternalOptions(
verbosity: Option[Int] = None,
// FIXME Should be removed, not a real option (not meant to be set from using directives)
strictBloopJsonCheck: Option[Boolean] = None,
interactive: Option[Boolean] = None,
interactive: Option[() => Interactive] = None,
javaClassNameVersionOpt: Option[String] = None,
/** Whether to keep the coursier.Resolution instance in [[scala.build.Artifacts]]
*
Expand Down

0 comments on commit 342c073

Please sign in to comment.