Skip to content
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

Add support for version arg #119

Merged
merged 3 commits into from
Dec 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions base/src/main/scala/co/uproot/abandon/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AbandonCLIConf(arguments: Seq[String]) extends ScallopConf(arguments) {
val filters = propsLong[String]("filter", descr="Transaction filters", keyName=" name")
val unversioned = opt[Boolean]("unversioned", short = 'X')
val quiet = opt[Boolean]("quiet", short = 'q')
// val trail = trailArg[String]()
val version = opt[Boolean]("version", noshort = true)
}

object SettingsHelper {
Expand Down Expand Up @@ -62,9 +62,7 @@ object SettingsHelper {
}
}

def getCompleteSettings(args: Seq[String], version: String): Either[String, Settings] = {
val cliConf = new AbandonCLIConf(args)
cliConf.verify()
def getCompleteSettings(cliConf: AbandonCLIConf, version: String): Either[String, Settings] = {
val configOpt = cliConf.config.toOption
val versionId = if (cliConf.unversioned.getOrElse(false)) {
None
Expand Down Expand Up @@ -329,6 +327,8 @@ case class DateRangeConstraint(dateFromOpt: Option[DateBound], dateToOpt: Option
}
}

class SettingsError(msg: String) extends RuntimeException(msg)

case class Settings(
inputs: Seq[String],
constraints: Seq[Constraint],
Expand Down
31 changes: 20 additions & 11 deletions cli/src/main/scala/co/uproot/abandon/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class ReportWriter(settings: Settings, outFiles: Seq[String]) {
}
}

object CLIMain {
object CLIMain {
def printBalReport(reportWriter: ReportWriter, balanceReport: BalanceReport) = {
val left = balanceReport.leftEntries.map(_.render)
val right = balanceReport.rightEntries.map(_.render)
Expand Down Expand Up @@ -149,15 +149,16 @@ object CLIMain {
}
reportWriter.endCodeBlock()
}

def buildId: String = {
"Base: " + BaseBuildInfo.version + " [" + BaseBuildInfo.builtAtString + "];" +
"CLI: " + CliBuildInfo.version + " [" + CliBuildInfo.builtAtString + "];"
}

def runAppThrows(args: Array[String]) {
val settingsResult = SettingsHelper.getCompleteSettings(args, buildId)
private def runApp(cliConf: AbandonCLIConf) {
val settingsResult = SettingsHelper.getCompleteSettings(cliConf, buildId)
settingsResult match {
case Left(errorMsg) => printErrAndExit(errorMsg)
case Left(errorMsg) => throw new SettingsError(errorMsg)
case Right(settings) =>
val (parseError, astEntries, processedFiles) = Processor.parseAll(settings.inputs, settings.quiet)
if (!parseError) {
Expand Down Expand Up @@ -225,27 +226,35 @@ object CLIMain {
}
}

def runApp(args: Array[String]) {
def run(args: Array[String]) {
val cliConf = new AbandonCLIConf(args)
cliConf.verify()

if (cliConf.version.supplied) {
println("Version: " + CliBuildInfo.version + " [" + CliBuildInfo.builtAtString + "]")
} else {
runApp(cliConf)
}
}

def main(args: Array[String]): Unit = {
try {
runAppThrows(args)
run(args)
} catch {
case a: AssertionError => printErrAndExit("Internal Assertion Error (please report a bug):" + a.getMessage)
case i: InputError => printErrAndExit("Input error: " + i.getMessage)
case i: ConstraintError => printErrAndExit("Constraint Failed: " + i.getMessage)
case e: NotImplementedError => printErrAndExit("Some functionality has not yet been implemented. We intend to implement it eventually. More details:\n" + e.getMessage)
case e: SettingsError => printErrAndExit("Configuration error: " + e.getMessage)
case e: Error => printErrAndExit("Unexpected error", e)
}
}

def printErrAndExit(msg: String, err:Error = null) = {
private def printErrAndExit(msg: String, err: Error = null) = {
println(Console.RED + Console.BOLD + msg + Console.RESET)
if (err != null) {
err.printStackTrace(Console.out)
}
System.exit(1)
}
}

object CLIApp extends App {
co.uproot.abandon.CLIMain.runApp(args)
}
11 changes: 11 additions & 0 deletions cli/src/test/scala/co/uproot/abandon/CLIMainTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.uproot.abandon

import org.scalatest.FlatSpec

class CLIMainTest extends FlatSpec {

behavior of "Abandon CLI with no-op args"
it should "handle version" in {
co.uproot.abandon.CLIMain.run(Array("--version"))
}
}
2 changes: 1 addition & 1 deletion cli/src/test/scala/co/uproot/abandon/CliTestRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CliTestSuite extends FunSuite {

def runTest(tc: TestCase) {
try {
co.uproot.abandon.CLIMain.runAppThrows(Array("-c", tc.conf) ++ tc.args ++ Array("-X", "-q"))
co.uproot.abandon.CLIMain.run(Array("-c", tc.conf) ++ tc.args ++ Array("-X", "-q"))
} catch {
case x: Exception => println("error: " + x); assert(false)
}
Expand Down
10 changes: 9 additions & 1 deletion gui/src/main/scala/co/uproot/abandon/UI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ object AbandonUI extends JFXApp {
}

try {
val settingsResult = SettingsHelper.getCompleteSettings(parameters.raw, buildId)
val cliConf = new AbandonCLIConf(parameters.raw)
cliConf.verify()

if (cliConf.version.supplied) {
val msg = "Version: " + GuiBuildInfo.version + " [" + GuiBuildInfo.builtAtString + "]"
System.err.println(msg)
}

val settingsResult = SettingsHelper.getCompleteSettings(cliConf, buildId)
settingsResult match {
case Left(errorMsg) => handleError("Error: " + errorMsg)
case Right(settings) =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/co/uproot/abandon/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Main extends App {
// ensureJFXIsAvailable()
AbandonUI.main(args.tail)
} else {
CLIMain.runApp(args)
CLIMain.main(args)
}

private def ensureJFXIsAvailable(): Unit = {
Expand Down