mirror of https://github.com/sbt/sbt.git
Merge pull request #3182 from eed3si9n/wip/interactive
Add InteractionService from sbt-core-next
This commit is contained in:
commit
934fabae25
|
|
@ -0,0 +1,24 @@
|
|||
package sbt
|
||||
|
||||
import sbt.internal.util.SimpleReader
|
||||
|
||||
trait CommandLineUIService extends InteractionService {
|
||||
override def readLine(prompt: String, mask: Boolean): Option[String] = {
|
||||
val maskChar = if (mask) Some('*') else None
|
||||
SimpleReader.readLine(prompt, maskChar)
|
||||
}
|
||||
// TODO - Implement this better.
|
||||
override def confirm(msg: String): Boolean = {
|
||||
object Assent {
|
||||
def unapply(in: String): Boolean = {
|
||||
(in == "y" || in == "yes")
|
||||
}
|
||||
}
|
||||
SimpleReader.readLine(msg + " (yes/no): ", None) match {
|
||||
case Some(Assent()) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object CommandLineUIService extends CommandLineUIService
|
||||
|
|
@ -258,6 +258,7 @@ object Defaults extends BuildCommon {
|
|||
.map(java.lang.Boolean.parseBoolean)
|
||||
.getOrElse(GCUtil.defaultForceGarbageCollection),
|
||||
minForcegcInterval :== GCUtil.defaultMinForcegcInterval,
|
||||
interactionService :== CommandLineUIService,
|
||||
serverPort := 5000 + (Hash
|
||||
.toHex(Hash(appConfiguration.value.baseDirectory.toString))
|
||||
.## % 1000)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package sbt
|
||||
|
||||
/**
|
||||
* InteractionService provides an abstration over standard input.
|
||||
* In the future this could be used to ask for inputs from
|
||||
* other forms of sbt clients such as thin clients and IDEs.
|
||||
*/
|
||||
abstract class InteractionService {
|
||||
|
||||
/** Prompts the user for input, optionally with a mask for characters. */
|
||||
def readLine(prompt: String, mask: Boolean): Option[String]
|
||||
|
||||
/** Ask the user to confirm something (yes or no) before continuing. */
|
||||
def confirm(msg: String): Boolean
|
||||
|
||||
// TODO - Ask for input with autocomplete?
|
||||
}
|
||||
|
|
@ -429,6 +429,7 @@ object Keys {
|
|||
val sbtBinaryVersion = SettingKey[String]("sbt-binary-version", "Defines the binary compatibility version substring.", BPlusSetting)
|
||||
val skip = TaskKey[Boolean]("skip", "For tasks that support it (currently only 'compile' and 'update'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.", BSetting)
|
||||
val templateResolverInfos = SettingKey[Seq[TemplateResolverInfo]]("templateResolverInfos", "Template resolvers used for 'new'.", BSetting)
|
||||
val interactionService = TaskKey[InteractionService]("interactionService", "Service used to ask for user input through the current user interface(s).", CTask)
|
||||
|
||||
// special
|
||||
val sessionVars = AttributeKey[SessionVar.Map]("session-vars", "Bindings that exist for the duration of the session.", Invisible)
|
||||
|
|
|
|||
Loading…
Reference in New Issue