1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package mill
import java.io.PrintStream
import ammonite.main.Cli
import ammonite.main.Cli.{formatBlock, genericSignature, replSignature}
import ammonite.ops._
import ammonite.util.Util
import mill.main.MainRunner
object Main {
case class Config(home: ammonite.ops.Path = pwd/'out/'ammonite,
colored: Option[Boolean] = None,
help: Boolean = false,
repl: Boolean = false,
watch: Boolean = false)
def main(args: Array[String]): Unit = {
val (result, _) = main0(args, None, () => false)
System.exit(if(result) 0 else 1)
}
def main0(args: Array[String],
mainRunner: Option[(Cli.Config, MainRunner)],
watchInterrupted: () => Boolean): (Boolean, Option[(Cli.Config, MainRunner)]) = {
import ammonite.main.Cli
val removed = Set("predef-code", "home", "no-home-predef")
val millArgSignature = Cli.genericSignature.filter(a => !removed(a.name))
Cli.groupArgs(
args.toList,
millArgSignature,
Cli.Config(remoteLogging = false)
) match{
case Left(msg) =>
System.err.println(msg)
(false, None)
case Right((cliConfig, _)) if cliConfig.help =>
val leftMargin = millArgSignature.map(ammonite.main.Cli.showArg(_).length).max + 2
System.out.println(
s"""Mill Build Tool
|usage: mill [mill-options] [target [target-options]]
|
|${formatBlock(millArgSignature, leftMargin).mkString(Util.newLine)}""".stripMargin
)
(true, None)
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
)
val runner = new mill.main.MainRunner(
config.copy(home = pwd / "out" / ".ammonite"),
System.out, System.err, System.in,
watchInterrupted,
mainRunner match{
case Some((c, mr)) if c.copy(storageBackend = null) == cliConfig.copy(storageBackend = null) =>
mr.lastEvaluator
case _ => None
}
)
if (repl){
runner.printInfo("Loading...")
(runner.watchLoop(isRepl = true, printing = false, _.run()), Some(cliConfig -> runner))
} else {
(runner.runScript(pwd / "build.sc", leftoverArgs), Some(cliConfig -> runner))
}
}
}
}
|