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

Output version and git hash for --version. #392

Merged
merged 1 commit into from
Feb 7, 2022
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
10 changes: 10 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
enablePlugins(JavaAppPackaging)
enablePlugins(BuildInfoPlugin)
enablePlugins(GitVersioning)

organization := "org.monarchinitiative"

Expand All @@ -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 ++= {
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
65 changes: 34 additions & 31 deletions src/main/scala/org/monarchinitiative/dosdp/cli/ZCaseApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

}

Expand Down