diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/src/mill/main/MagicScopt.scala | 46 | ||||
-rw-r--r-- | main/src/mill/main/MainModule.scala | 15 | ||||
-rw-r--r-- | main/src/mill/main/MainRunner.scala | 3 | ||||
-rw-r--r-- | main/src/mill/main/MainScopts.scala | 49 |
4 files changed, 58 insertions, 55 deletions
diff --git a/main/src/mill/main/MagicScopt.scala b/main/src/mill/main/MagicScopt.scala deleted file mode 100644 index e18816c8..00000000 --- a/main/src/mill/main/MagicScopt.scala +++ /dev/null @@ -1,46 +0,0 @@ -package mill.main -import mill.define.ExternalModule -import mill.eval.{Evaluator, PathRef} -import mill.util.ParseArgs - -object MagicScopt{ - - - case class Tasks[T](value: Seq[mill.define.NamedTask[T]]) -} -class EvaluatorScopt[T]() - extends scopt.Read[mill.eval.Evaluator[T]]{ - def arity = 0 - def reads = s => try{ - Evaluator.currentEvaluator.get.asInstanceOf[mill.eval.Evaluator[T]] - } -} -class TargetScopt[T]() - extends scopt.Read[MagicScopt.Tasks[T]]{ - def arity = 0 - def reads = s => { - val rootModule = Evaluator.currentEvaluator.get.rootModule - val d = rootModule.millDiscover - val (expanded, leftover) = ParseArgs(Seq(s)).fold(e => throw new Exception(e), identity) - val resolved = expanded.map{ - case (Some(scoping), segments) => - val moduleCls = rootModule.getClass.getClassLoader.loadClass(scoping.render + "$") - val externalRootModule = moduleCls.getField("MODULE$").get(moduleCls).asInstanceOf[ExternalModule] - val crossSelectors = segments.value.map { - case mill.define.Segment.Cross(x) => x.toList.map(_.toString) - case _ => Nil - } - mill.main.Resolve.resolve(segments.value.toList, externalRootModule, d, leftover, crossSelectors.toList, Nil) - case (None, segments) => - val crossSelectors = segments.value.map { - case mill.define.Segment.Cross(x) => x.toList.map(_.toString) - case _ => Nil - } - mill.main.Resolve.resolve(segments.value.toList, rootModule, d, leftover, crossSelectors.toList, Nil) - } - mill.util.EitherOps.sequence(resolved) match{ - case Left(s) => throw new Exception(s) - case Right(ts) => MagicScopt.Tasks(ts.flatten).asInstanceOf[MagicScopt.Tasks[T]] - } - } -}
\ No newline at end of file diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index 012ecce5..04cd3553 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -6,16 +6,19 @@ import mill.util.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.TargetScopt[T]() + implicit def millScoptTargetReads[T] = new mill.main.Tasks.Scopt[T]() implicit def millScoptEvaluatorReads[T] = new mill.main.EvaluatorScopt[T]() - mill.define.Ctx.make - def resolve(targets: mill.main.MagicScopt.Tasks[Any]*) = mill.T.command{ + + def resolve(targets: mill.main.Tasks[Any]*) = mill.T.command{ targets.flatMap(_.value).foreach(println) } def describe(evaluator: mill.eval.Evaluator[Any], - targets: mill.main.MagicScopt.Tasks[Any]*) = mill.T.command{ + targets: mill.main.Tasks[Any]*) = mill.T.command{ for{ t <- targets target <- t.value @@ -35,7 +38,7 @@ trait MainModule extends mill.Module{ } } def all(evaluator: mill.eval.Evaluator[Any], - targets: mill.main.MagicScopt.Tasks[Any]*) = mill.T.command{ + targets: mill.main.Tasks[Any]*) = mill.T.command{ val (watched, res) = RunScript.evaluate( evaluator, mill.util.Strict.Agg.from(targets.flatMap(_.value)) @@ -43,7 +46,7 @@ trait MainModule extends mill.Module{ Watched((), watched) } def show(evaluator: mill.eval.Evaluator[Any], - targets: mill.main.MagicScopt.Tasks[Any]*) = mill.T.command{ + targets: mill.main.Tasks[Any]*) = mill.T.command{ val (watched, res) = mill.main.RunScript.evaluate( evaluator, mill.util.Strict.Agg.from(targets.flatMap(_.value)) diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index c073e583..e35c1776 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -100,9 +100,6 @@ class MainRunner(config: ammonite.main.Cli.Config, | def $$main() = Iterator[String]() | | implicit def millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type] - | // 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) |} | |sealed trait $wrapName extends mill.main.MainModule{ diff --git a/main/src/mill/main/MainScopts.scala b/main/src/mill/main/MainScopts.scala new file mode 100644 index 00000000..acf48d05 --- /dev/null +++ b/main/src/mill/main/MainScopts.scala @@ -0,0 +1,49 @@ +package mill.main +import mill.define.ExternalModule +import mill.eval.{Evaluator, PathRef} +import mill.util.ParseArgs + +case class Tasks[T](value: Seq[mill.define.NamedTask[T]]) + +object Tasks{ + + class Scopt[T]() + extends scopt.Read[Tasks[T]] { + def arity = 0 + + def reads = s => { + val rootModule = Evaluator.currentEvaluator.get.rootModule + val d = rootModule.millDiscover + val (expanded, leftover) = ParseArgs(Seq(s)).fold(e => throw new Exception(e), identity) + val resolved = expanded.map { + case (Some(scoping), segments) => + val moduleCls = rootModule.getClass.getClassLoader.loadClass(scoping.render + "$") + val externalRootModule = moduleCls.getField("MODULE$").get(moduleCls).asInstanceOf[ExternalModule] + val crossSelectors = segments.value.map { + case mill.define.Segment.Cross(x) => x.toList.map(_.toString) + case _ => Nil + } + mill.main.Resolve.resolve(segments.value.toList, externalRootModule, d, leftover, crossSelectors.toList, Nil) + case (None, segments) => + val crossSelectors = segments.value.map { + case mill.define.Segment.Cross(x) => x.toList.map(_.toString) + case _ => Nil + } + mill.main.Resolve.resolve(segments.value.toList, rootModule, d, leftover, crossSelectors.toList, Nil) + } + mill.util.EitherOps.sequence(resolved) match { + case Left(s) => throw new Exception(s) + case Right(ts) => Tasks(ts.flatten).asInstanceOf[Tasks[T]] + } + } + } + +} + +class EvaluatorScopt[T]() + extends scopt.Read[mill.eval.Evaluator[T]]{ + def arity = 0 + def reads = s => try{ + Evaluator.currentEvaluator.get.asInstanceOf[mill.eval.Evaluator[T]] + } +} |