diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/src/mill/Main.scala | 17 | ||||
-rw-r--r-- | main/src/mill/main/MainModule.scala | 16 | ||||
-rw-r--r-- | main/src/mill/main/MainRunner.scala | 17 | ||||
-rw-r--r-- | main/test/src/mill/util/ScriptTestSuite.scala | 2 |
4 files changed, 18 insertions, 34 deletions
diff --git a/main/src/mill/Main.scala b/main/src/mill/Main.scala index 3025994c..fceb5c9f 100644 --- a/main/src/mill/Main.scala +++ b/main/src/mill/Main.scala @@ -15,18 +15,8 @@ object Main { import ammonite.main.Cli - var show = false - val showCliArg = Cli.Arg[Cli.Config, Unit]( - "show", - None, - "Display the json-formatted value of the given target, if any", - (x, _) => { - show = true - x - } - ) val removed = Set("predef-code", "home", "no-home-predef") - val millArgSignature = (Cli.genericSignature :+ showCliArg).filter(a => !removed(a.name)) + val millArgSignature = Cli.genericSignature.filter(a => !removed(a.name)) Cli.groupArgs( args.toList, millArgSignature, @@ -65,10 +55,7 @@ object Main { welcomeBanner = None ) - val runner = new mill.main.MainRunner( - config, show, - System.out, System.err, System.in - ) + val runner = new mill.main.MainRunner(config, System.out, System.err, System.in) if (repl){ runner.printInfo("Loading...") runner.runRepl() diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index 04cd3553..bd8befb3 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -1,14 +1,9 @@ package mill.main -import mill.util -import mill.main.RunScript -import mill.util.Watched +import mill.util.{PrintLogger, Watched} import pprint.{Renderer, Truncated} trait MainModule extends mill.Module{ - // Need to wrap the returned Module in Some(...) to make sure it - // doesn't get picked up during reflective child-module discovery - val millSelf = Some(this) implicit def millDiscover: mill.define.Discover[_] implicit def millScoptTargetReads[T] = new mill.main.Tasks.Scopt[T]() @@ -48,7 +43,14 @@ trait MainModule extends mill.Module{ def show(evaluator: mill.eval.Evaluator[Any], targets: mill.main.Tasks[Any]*) = mill.T.command{ val (watched, res) = mill.main.RunScript.evaluate( - evaluator, + // When using `show`, redirect all stdout of the evaluated tasks so the + // printed JSON is the only thing printed to stdout. + evaluator.copy( + log = evaluator.log match{ + case PrintLogger(c1, c2, o, i, e) => PrintLogger(c1, c2, e, i, e) + case l => l + } + ), mill.util.Strict.Agg.from(targets.flatMap(_.value)) ) for(json <- res.right.get.flatMap(_._2)){ diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index e35c1776..c4d50d46 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -17,7 +17,6 @@ import upickle.Js * `scriptCodeWrapper` or with a persistent evaluator between runs. */ class MainRunner(config: ammonite.main.Cli.Config, - show: Boolean, outprintStream: PrintStream, errPrintStream: PrintStream, stdIn: InputStream) @@ -42,7 +41,7 @@ class MainRunner(config: ammonite.main.Cli.Config, new PrintLogger( colors != ammonite.util.Colors.BlackWhite, colors, - if (show) errPrintStream else outprintStream, + outprintStream, errPrintStream, errPrintStream ) @@ -62,15 +61,7 @@ class MainRunner(config: ammonite.main.Cli.Config, override def handleWatchRes[T](res: Res[T], printing: Boolean) = { res match{ - case Res.Success(value) => -// if (show){ -// for(json <- value.asInstanceOf[Seq[Js.Value]]){ -// outprintStream.println(json) -// } -// } - - true - + case Res.Success(value) => true case _ => super.handleWatchRes(res, printing) } @@ -99,6 +90,10 @@ class MainRunner(config: ammonite.main.Cli.Config, | // even if it does nothing... | def $$main() = Iterator[String]() | + | // Need to wrap the returned Module in Some(...) to make sure it + | // doesn't get picked up during reflective child-module discovery + | def millSelf = Some(this) + | | implicit def millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type] |} | diff --git a/main/test/src/mill/util/ScriptTestSuite.scala b/main/test/src/mill/util/ScriptTestSuite.scala index 916d3af6..292c09be 100644 --- a/main/test/src/mill/util/ScriptTestSuite.scala +++ b/main/test/src/mill/util/ScriptTestSuite.scala @@ -15,7 +15,7 @@ abstract class ScriptTestSuite extends TestSuite{ // val stdOutErr = new PrintStream(System.out) val stdIn = new ByteArrayInputStream(Array()) val runner = new mill.main.MainRunner( - ammonite.main.Cli.Config(wd = workspacePath), false, + ammonite.main.Cli.Config(wd = workspacePath), stdOutErr, stdOutErr, stdIn ) def eval(s: String*) = runner.runScript(workspacePath / "build.sc", s.toList) |