2014-12-31 26 views
4

我正在使用sbt來構建我的Scala項目,我正在尋找一種方法來按子字符串篩選任何命令(如compile)的輸出。特別是,我想結合sbt命令使用grep。例如> compile | grep MyFile.scala,應該只打印提到MyFile.scala的行。如何在sbt中執行grep

有沒有辦法做到這一點?

$ sbt --version 
sbt launcher version 0.13.5 
+2

儘管它可能不能完全滿足您的需求,但您是否查看了sbt的'last-grep'命令? – edi

+0

謝謝。它幫助了我。我想這對我來說是最好的選擇。我不確定我所問的是否可能。 –

回答

0

我不知道從sbt控制檯內部執行它,但從你的外殼怎麼樣?

$ sbt "tasks" | grep 'clean' 

clean Deletes files produced by the build, such as generated sources, compiled classes, and task caches. 

或爲子你提到:

$ sbt "tasks" | grep 'class' 
    clean Deletes files produced by the build, such as generated sources, compiled classes, and task caches. 

    console Starts the Scala interpreter with the project classes on the classpath. 

    consoleProject Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports. 

    consoleQuick Starts the Scala interpreter with the project dependencies on the classpath. 

    run Runs a main class, passing along arguments provided on the command line. 

    runMain Runs the main class selected by the first argument, passing the remaining arguments to the main method. 
+0

是的,我知道這個解決方案,但重新啓動'sbt'一直有點乏味。我正在尋找一種方法來從sbt shell中完成它 –

5

到grep SBT的交互模式(SBT 0.13.11測試)輸出的最好方法是使用last-grep

這將重新打印最後一個命令的輸出,它將採用不同的類似grep的參數。

相關問題