-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding clean as a default task #253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package mill.main | ||
|
||
import ammonite.ops.Path | ||
import mill.define.{NamedTask, Task} | ||
import mill.eval.{Evaluator, Result} | ||
import mill.util.{EitherOps, ParseArgs, PrintLogger, Watched} | ||
import mill.util.{PrintLogger, Watched} | ||
import pprint.{Renderer, Truncated} | ||
import upickle.Js | ||
|
||
import scala.util.{Failure, Success, Try} | ||
object MainModule{ | ||
def resolveTasks[T](evaluator: Evaluator[Any], targets: Seq[String], multiSelect: Boolean) | ||
(f: List[NamedTask[Any]] => T) = { | ||
|
@@ -31,6 +34,9 @@ trait MainModule extends mill.Module{ | |
implicit def millScoptTasksReads[T] = new mill.main.Tasks.Scopt[T]() | ||
implicit def millScoptEvaluatorReads[T] = new mill.main.EvaluatorScopt[T]() | ||
|
||
private val OutDir: String = "out" | ||
private val BuildFile: String = "build.sc" | ||
|
||
/** | ||
* Resolves a mill query string and prints out the tasks it resolves to. | ||
*/ | ||
|
@@ -173,4 +179,34 @@ trait MainModule extends mill.Module{ | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Deletes the given targets from the out directory. Providing no targets will clean everything. | ||
*/ | ||
def clean(targets: String*) = mill.T.command { | ||
val result = Try { | ||
if (ammonite.ops.ls(ammonite.ops.pwd).contains(ammonite.ops.pwd / BuildFile)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are doing validation on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
targets match { | ||
case Nil => | ||
remove(List(ammonite.ops.pwd / OutDir)) | ||
case _ => | ||
remove(targets | ||
.map(_.replace(".", "/")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use |
||
.map(target => Path(target, ammonite.ops.pwd / OutDir)) | ||
.toList) | ||
} | ||
} else { | ||
Result.Failure(s"Cannot find $BuildFile") | ||
} | ||
} | ||
result match { | ||
case Success(r) => r | ||
case Failure(error) => Result.Exception(error, new Result.OuterStack(error.getStackTrace)) | ||
} | ||
} | ||
|
||
private def remove(paths: List[Path]): Result[String] = { | ||
paths.filter(ammonite.ops.exists).foreach(ammonite.ops.rm) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice. |
||
Result.Success("Targets cleaned") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea why you are wrapping this in a
Try
; you just need to return a simpleResult
objectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ammonite functions call things which can throw exceptions. Is it acceptable to let those exceptions be thrown?