From 02e64b943b90387993f8f7bd7e3cd265ee569d27 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 26 Feb 2018 19:58:48 -0800 Subject: force build REPL to be run using -i/--interactive --- docs/pages/1 - Intro to Mill.md | 2 +- main/src/mill/Main.scala | 60 ++++++++++++++++++++++------------------- readme.md | 3 ++- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/docs/pages/1 - Intro to Mill.md b/docs/pages/1 - Intro to Mill.md index 65a83b8a..b2ffe0ec 100644 --- a/docs/pages/1 - Intro to Mill.md +++ b/docs/pages/1 - Intro to Mill.md @@ -398,7 +398,7 @@ your build file itself. ## The Build Repl ```bash -$ mill +$ mill -i Loading... @ foo res1: foo.type = ammonite.predef.build#foo:2 diff --git a/main/src/mill/Main.scala b/main/src/mill/Main.scala index 91fe862c..4a2ccba0 100644 --- a/main/src/mill/Main.scala +++ b/main/src/mill/Main.scala @@ -137,36 +137,42 @@ object Main { case Right((cliConfig, leftoverArgs)) => val repl = leftoverArgs.isEmpty - val config = - if(!repl) cliConfig - else cliConfig.copy( - predefCode = - """import $file.build, build._ - |implicit val replApplyHandler = mill.main.ReplApplyHandler( - | interp.colors(), - | repl.pprinter(), - | build.millSelf.get, - | build.millDiscover - |) - |repl.pprinter() = replApplyHandler.pprinter - |import replApplyHandler.generatedEval._ - | - """.stripMargin, - welcomeBanner = None + if (repl && stdin == DummyInputStream) { + stderr.println("Build repl needs to be run with the -i/--interactive flag") + (false, stateCache) + }else{ + val config = + if(!repl) cliConfig + else cliConfig.copy( + predefCode = + """import $file.build, build._ + |implicit val replApplyHandler = mill.main.ReplApplyHandler( + | interp.colors(), + | repl.pprinter(), + | build.millSelf.get, + | build.millDiscover + |) + |repl.pprinter() = replApplyHandler.pprinter + |import replApplyHandler.generatedEval._ + | + """.stripMargin, + welcomeBanner = None + ) + + val runner = new mill.main.MainRunner( + config.copy(colored = Some(mainInteractive)), + stdout, stderr, stdin, + stateCache ) - val runner = new mill.main.MainRunner( - config.copy(colored = Some(mainInteractive)), - stdout, stderr, stdin, - stateCache - ) + if (repl){ + runner.printInfo("Loading...") + (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) + } else { + (runner.runScript(pwd / "build.sc", leftoverArgs), runner.stateCache) + } + } - if (repl){ - runner.printInfo("Loading...") - (runner.watchLoop(isRepl = true, printing = false, _.run()), runner.stateCache) - } else { - (runner.runScript(pwd / "build.sc", leftoverArgs), runner.stateCache) - } } } } diff --git a/readme.md b/readme.md index 8a416035..fa68fd85 100644 --- a/readme.md +++ b/readme.md @@ -177,7 +177,8 @@ Mill provides a build REPL, which lets you explore the build interactively and run `Target`s from Scala code: ```scala -lihaoyi mill$ target/bin/mill +$ mill -i + Loading... Compiling (synthetic)/ammonite/predef/interpBridge.sc Compiling (synthetic)/ammonite/predef/replBridge.sc -- cgit v1.2.3