scala - sbt:静默执行initialCommands

标签 scala sbt

是否可以执行initialCommandsconsole默默地完成任务,即好像

:silent

val $session = new foo.bar.Session()
import $session._
import $session.lib._

:silent

将这些命令放入 initialCommands但不起作用,因为 :<command>命令显然不能在 initialCommands 中使用:

Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> <console>:2: error: illegal start of definition
:silent
^
Interpreter encountered errors during initialization!

[error] (Thread-1) java.lang.InterruptedException

java.lang.InterruptedException
    at java.util.concurrent.SynchronousQueue.put(SynchronousQueue.java:879)
    at scala.tools.nsc.interpreter.SplashLoop.run(InteractiveReader.scala:77)
    at java.lang.Thread.run(Thread.java:745)

最佳答案

不幸的是,从 0.13.13 开始,sbt 在创建解释器时,以及在控制台有机会将解释器绑定(bind)为 $intp 之前,就提前运行了 initialCommands >.

这很接近:

$ sbt -Dscala.repl.maxprintstring=-1
[info] Set current project to sbt-test (in build file:/home/apm/tmp/sbt-test/)
> console
[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> ...

scala> Future(42)
...

scala> $intp.isettings.max
maxAutoprintCompletion   maxPrintString

scala> $intp.isettings.maxPrintString = 1000
$intp.isettings.maxPrintString: Int = 1000

scala> "hi"*1000
res0: String = hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi...

scala> Future(42)
res1: scala.concurrent.Future[Int] = Future(Success(42))

maxPrintString 设置为零并不会截断所有内容,包括省略号,这是一个错误功能,它始终是残留的。

关于scala - sbt:静默执行initialCommands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42635819/

相关文章:

sbt - 如何在SBT 0.13.1中将命令行args传递给程序?

playframework - 强制 Play Framework 依赖

scala - 在 Scala 3 中提取元组的子集

scala - MonotonicallyIncreasingId 输出变化范围广泛

scala - 在 Scala 中转换多个 optional 值

scala - 多个包定义

scala - 让 sbt 将 javadocs 和依赖源放在类路径上

scala - 为什么 sbt.Extracted 在 append 方法中删除了之前定义的 TaskKey?

scala - 已弃用 sbt 包中的特征构建 : Use . sbt 格式

scala - 在 Scala 中的 firstCompletedOf 中需要什么是隐式的