diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/mill/define/Task.scala | 12 | ||||
-rw-r--r-- | core/src/mill/util/EnclosingClass.scala | 15 | ||||
-rw-r--r-- | core/src/mill/util/ParseArgs.scala | 33 |
3 files changed, 26 insertions, 34 deletions
diff --git a/core/src/mill/define/Task.scala b/core/src/mill/define/Task.scala index 230089bf..33f94453 100644 --- a/core/src/mill/define/Task.scala +++ b/core/src/mill/define/Task.scala @@ -3,23 +3,13 @@ package mill.define import ammonite.main.Router.Overrides import mill.define.Applicative.Applyable import mill.eval.{PathRef, Result} +import mill.util.EnclosingClass import sourcecode.Compat.Context import upickle.default.{ReadWriter => RW, Reader => R, Writer => W} import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context -case class EnclosingClass(value: Class[_]) -object EnclosingClass{ - def apply()(implicit c: EnclosingClass) = c.value - implicit def generate: EnclosingClass = macro impl - def impl(c: Context): c.Tree = { - import c.universe._ - val cls = c.internal.enclosingOwner.owner.asType.asClass -// q"new _root_.mill.define.EnclosingClass(classOf[$cls])" - q"new _root_.mill.define.EnclosingClass(this.getClass)" - } -} /** * Models a single node in the Mill build graph, with a list of inputs and a diff --git a/core/src/mill/util/EnclosingClass.scala b/core/src/mill/util/EnclosingClass.scala new file mode 100644 index 00000000..a69cc525 --- /dev/null +++ b/core/src/mill/util/EnclosingClass.scala @@ -0,0 +1,15 @@ +package mill.util + +import sourcecode.Compat.Context +import language.experimental.macros +case class EnclosingClass(value: Class[_]) +object EnclosingClass{ + def apply()(implicit c: EnclosingClass) = c.value + implicit def generate: EnclosingClass = macro impl + def impl(c: Context): c.Tree = { + import c.universe._ + val cls = c.internal.enclosingOwner.owner.asType.asClass + // q"new _root_.mill.define.EnclosingClass(classOf[$cls])" + q"new _root_.mill.util.EnclosingClass(this.getClass)" + } +} diff --git a/core/src/mill/util/ParseArgs.scala b/core/src/mill/util/ParseArgs.scala index 315edabc..9137923a 100644 --- a/core/src/mill/util/ParseArgs.scala +++ b/core/src/mill/util/ParseArgs.scala @@ -5,50 +5,38 @@ import mill.define.{Segment, Segments} object ParseArgs { - def apply(scriptArgs: Seq[String]) - : Either[String, (List[(Option[Segments], Segments)], Seq[String])] = { - val (selectors, args, isMultiSelectors) = extractSelsAndArgs(scriptArgs) + def apply(scriptArgs: Seq[String], + multiSelect: Boolean): Either[String, (List[(Option[Segments], Segments)], Seq[String])] = { + val (selectors, args) = extractSelsAndArgs(scriptArgs, multiSelect) for { _ <- validateSelectors(selectors) expandedSelectors <- EitherOps .sequence(selectors.map(expandBraces)) .map(_.flatten) - _ <- validateExpanded(expandedSelectors, isMultiSelectors) selectors <- EitherOps.sequence(expandedSelectors.map(extractSegments)) } yield (selectors.toList, args) } - def extractSelsAndArgs( - scriptArgs: Seq[String]): (Seq[String], Seq[String], Boolean) = { - val multiFlags = Seq("--all", "--seq") - val isMultiSelectors = scriptArgs.headOption.exists(multiFlags.contains) + def extractSelsAndArgs(scriptArgs: Seq[String], + multiSelect: Boolean): (Seq[String], Seq[String]) = { - if (isMultiSelectors) { + if (multiSelect) { val dd = scriptArgs.indexOf("--") - val selectors = (if (dd == -1) scriptArgs - else scriptArgs.take(dd)).filterNot(multiFlags.contains) + val selectors = if (dd == -1) scriptArgs else scriptArgs.take(dd) val args = if (dd == -1) Seq.empty else scriptArgs.drop(dd + 1) - (selectors, args, isMultiSelectors) + (selectors, args) } else { - (scriptArgs.take(1), scriptArgs.drop(1), isMultiSelectors) + (scriptArgs.take(1), scriptArgs.drop(1)) } } - private def validateSelectors( - selectors: Seq[String]): Either[String, Unit] = { + private def validateSelectors(selectors: Seq[String]): Either[String, Unit] = { if (selectors.isEmpty || selectors.exists(_.isEmpty)) Left("Selector cannot be empty") else Right(()) } - private def validateExpanded(expanded: Seq[String], - isMulti: Boolean): Either[String, Unit] = { - if (!isMulti && expanded.length > 1) - Left("Please use --all flag to run multiple tasks") - else Right(()) - } - def expandBraces(selectorString: String): Either[String, List[String]] = { parseBraceExpansion(selectorString) match { case f: Parsed.Failure => Left(s"Parsing exception ${f.msg}") @@ -139,5 +127,4 @@ object ParseArgs { } query.parse(input) } - } |