diff --git a/build.sbt b/build.sbt index b7b6944..e917356 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,6 @@ enablePlugins(JavaAppPackaging) +enablePlugins(BuildInfoPlugin) +enablePlugins(GitVersioning) organization := "org.monarchinitiative" @@ -16,6 +18,14 @@ javaOptions += "-Xmx8G" testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework") +val gitCommitString = SettingKey[String]("gitCommit") + +gitCommitString := git.gitHeadCommit.value.getOrElse("Not Set") + +buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, gitCommitString) + +buildInfoPackage := "org.monarchinitiative.dosdp.cli" + val zioVersion = "1.0.12" libraryDependencies ++= { diff --git a/project/plugins.sbt b/project/plugins.sbt index e662149..6073d9e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,3 @@ addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.7") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2") diff --git a/src/main/scala/org/monarchinitiative/dosdp/cli/ZCaseApp.scala b/src/main/scala/org/monarchinitiative/dosdp/cli/ZCaseApp.scala index 38fbb1a..ef8f5c8 100644 --- a/src/main/scala/org/monarchinitiative/dosdp/cli/ZCaseApp.scala +++ b/src/main/scala/org/monarchinitiative/dosdp/cli/ZCaseApp.scala @@ -139,37 +139,40 @@ abstract class ZCommandAppWithPreCommand[D, T](implicit def progName: String = Help[D].progName - override def run(args: List[String]): ZIO[ZEnv, Nothing, ExitCode] = - commandParser.withHelp.detailedParse(args.toVector)(beforeCommandParser.withHelp) match { - case Left(err) => - error(err).orDie - case Right((WithHelp(true, _, _), _, _)) => - usageAsked().orDie - case Right((WithHelp(_, true, _), _, _)) => - helpAsked().orDie - case Right((WithHelp(false, false, Left(err)), _, _)) => - error(err).orDie - case Right((WithHelp(false, false, Right(d)), dArgs, optCmd)) => - beforeCommand(d, dArgs).flatMap { - case Some(exitCode) => IO.succeed(exitCode) - case None => - optCmd - .map { - case Left(err) => - error(err).orDie - case Right((c, WithHelp(true, _, _), _)) => - commandUsageAsked(c).orDie - case Right((c, WithHelp(_, true, _), _)) => - commandHelpAsked(c).orDie - case Right((_, WithHelp(_, _, t), commandArgs)) => - t.fold( - error(_).orDie, - run(_, commandArgs) - ) - } - .getOrElse(ZIO.succeed(ExitCode.success)) - }.orDie - } + override def run(args: List[String]): ZIO[ZEnv, Nothing, ExitCode] = { + if (args == List("--version")) ZIO.succeed(println(org.monarchinitiative.dosdp.cli.BuildInfo.toString)).exitCode + else + commandParser.withHelp.detailedParse(args.toVector)(beforeCommandParser.withHelp) match { + case Left(err) => + error(err).orDie + case Right((WithHelp(true, _, _), _, _)) => + usageAsked().orDie + case Right((WithHelp(_, true, _), _, _)) => + helpAsked().orDie + case Right((WithHelp(false, false, Left(err)), _, _)) => + error(err).orDie + case Right((WithHelp(false, false, Right(d)), dArgs, optCmd)) => + beforeCommand(d, dArgs).flatMap { + case Some(exitCode) => IO.succeed(exitCode) + case None => + optCmd + .map { + case Left(err) => + error(err).orDie + case Right((c, WithHelp(true, _, _), _)) => + commandUsageAsked(c).orDie + case Right((c, WithHelp(_, true, _), _)) => + commandHelpAsked(c).orDie + case Right((_, WithHelp(_, _, t), commandArgs)) => + t.fold( + error(_).orDie, + run(_, commandArgs) + ) + } + .getOrElse(ZIO.succeed(ExitCode.success)) + }.orDie + } + } }