52 lines
1.7 KiB
Scala
52 lines
1.7 KiB
Scala
package com.minres.tgc.hammer
|
|
|
|
import ch.qos.logback.classic.Level
|
|
import com.minres.tgc.hammer.cli.{HammerConf, MySubcommand}
|
|
import com.minres.tgc.hammer.util.AssertException
|
|
import com.typesafe.scalalogging.Logger
|
|
import org.slf4j.LoggerFactory
|
|
|
|
import scala.compiletime.uninitialized
|
|
|
|
object Main {
|
|
var conf: HammerConf = uninitialized
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
val logger = Logger("TGCHammer")
|
|
conf = new HammerConf(args.toIndexedSeq)
|
|
|
|
val logLevel = conf.verbose() match {
|
|
case 0 => Level.WARN
|
|
case 1 => Level.INFO
|
|
case 2 => Level.DEBUG
|
|
case _ => Level.TRACE
|
|
}
|
|
LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[ch.qos.logback.classic.Logger].setLevel(logLevel)
|
|
|
|
logger.trace(s"Creating output directory ${Global.OUT_DIR}")
|
|
if (conf.emptyOutputDir()) os.remove.all(Global.OUT_DIR)
|
|
os.makeDir.all(Global.OUT_DIR)
|
|
os.makeDir.all(Global.LOG_DIR)
|
|
logger.trace(s"Creating temp directory ${Global.TMP_DIR}")
|
|
os.makeDir.all(Global.TMP_DIR)
|
|
conf.subcommand match {
|
|
case Some(c: MySubcommand) =>
|
|
logger.info(s"Executing subcommand ${c.name}")
|
|
val tasks = c.getRequiredTasks
|
|
logger.debug(s"Subcommand requires ${tasks.size} tasks")
|
|
try {
|
|
tasks.foreach(_.run())
|
|
} catch {
|
|
case e: AssertException =>
|
|
logger.error(s"Error during task execution, see above!")
|
|
case e: Exception =>
|
|
logger.error(s"General exception ${e.getMessage}")
|
|
e.printStackTrace()
|
|
}
|
|
case _ =>
|
|
logger.error(s"Found no subcommand, see help below")
|
|
conf.printHelp()
|
|
}
|
|
}
|
|
}
|