Merge pull request #161 from alexarchambault/topic/cli-errors

Add --force option to the fetch CLI command, better error reporting
This commit is contained in:
Alexandre Archambault 2016-02-23 16:11:18 +01:00
commit ec37fedfa3
2 changed files with 38 additions and 21 deletions

View File

@ -95,11 +95,13 @@ case class Fetch(
@Help("Print java -cp compatible output")
@Short("p")
classpath: Boolean,
@Help("Fetch artifacts even if the resolution is errored")
force: Boolean,
@Recurse
common: CommonOptions
) extends CoursierCommand {
val helper = new Helper(common, remainingArgs)
val helper = new Helper(common, remainingArgs, ignoreErrors = force)
val files0 = helper.fetch(sources = sources, javadoc = javadoc)

View File

@ -59,7 +59,8 @@ object Util {
class Helper(
common: CommonOptions,
rawDependencies: Seq[String],
printResultStdout: Boolean = false
printResultStdout: Boolean = false,
ignoreErrors: Boolean = false
) {
import common._
import Helper.errPrintln
@ -236,25 +237,6 @@ class Helper(
logger.foreach(_.stop())
// FIXME Better to print all the messages related to the exit conditions below, then exit
// rather than exit at the first one
exitIf(!res.isDone) {
errPrintln(s"Maximum number of iteration reached!")
sys.exit(1)
}
exitIf(res.errors.nonEmpty) {
s"\nError:\n" +
res.errors.map { case (dep, errs) =>
s" ${dep.module}:${dep.version}:\n${errs.map(" " + _.replace("\n", " \n")).mkString("\n")}"
}.mkString("\n")
}
exitIf(res.conflicts.nonEmpty) {
s"\nConflict:\n${Print.dependenciesUnknownConfigs(res.conflicts.toVector, projCache)}"
}
val trDeps = res.minDependencies.toVector
lazy val projCache = res.projectCache.mapValues { case (_, p) => p }
@ -268,6 +250,39 @@ class Helper(
errPrintln(depsStr)
}
var anyError = false
if (!res.isDone) {
anyError = true
errPrintln("\nMaximum number of iterations reached!")
}
if (res.errors.nonEmpty) {
anyError = true
errPrintln(
s"\nError:\n" +
res.errors.map {
case (dep, errs) =>
s" ${dep.module}:${dep.version}:\n${errs.map(" " + _.replace("\n", " \n")).mkString("\n")}"
}.mkString("\n")
)
}
if (res.conflicts.nonEmpty) {
anyError = true
errPrintln(
s"\nConflict:\n" +
Print.dependenciesUnknownConfigs(res.conflicts.toVector, projCache)
)
}
if (anyError) {
if (ignoreErrors)
errPrintln("Ignoring errors")
else
sys.exit(1)
}
def fetch(
sources: Boolean,
javadoc: Boolean,