Add a version command-line option (#99)
* [sbt] make name and version available within Scala Available as `thorp.BuildInfo._` * [core] ConfigOption Add Version option * [cli] ParseArgs add command-line options `-V` and `--version` * [core] ConfigQuery add showVersion query * [cli] Program shows version then exit * [cli] Main don't show "Done"
This commit is contained in:
parent
561966218c
commit
5df752047f
7 changed files with 30 additions and 8 deletions
|
@ -67,6 +67,11 @@ lazy val cli = (project in file("cli"))
|
|||
.settings(applicationSettings)
|
||||
.settings(commandLineParsing)
|
||||
.settings(testDependencies)
|
||||
.enablePlugins(BuildInfoPlugin)
|
||||
.settings(
|
||||
buildInfoKeys := Seq[BuildInfoKey](name, version),
|
||||
buildInfoPackage := "thorp"
|
||||
)
|
||||
.settings(Seq(
|
||||
assemblyOption in assembly := (
|
||||
assemblyOption in assembly).value
|
||||
|
|
|
@ -13,7 +13,7 @@ object Main extends IOApp {
|
|||
.guaranteeCase {
|
||||
case Canceled => exitCaseLogger.warn("Interrupted")
|
||||
case Error(e) => exitCaseLogger.error(e.getMessage)
|
||||
case Completed => exitCaseLogger.info("Done")
|
||||
case Completed => IO.unit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@ object ParseArgs {
|
|||
OParser.sequence(
|
||||
programName("thorp"),
|
||||
head("thorp"),
|
||||
opt[Unit]('V', "version")
|
||||
.action((_, cos) => ConfigOption.Version :: cos)
|
||||
.text("Show version"),
|
||||
opt[String]('s', "source")
|
||||
.action((str, cos) => ConfigOption.Source(Paths.get(str)) :: cos)
|
||||
.text("Source directory to sync to destination"),
|
||||
|
|
|
@ -11,6 +11,10 @@ trait Program {
|
|||
|
||||
def apply(cliOptions: Seq[ConfigOption]): IO[ExitCode] = {
|
||||
implicit val logger: Logger = new PrintLogger()
|
||||
if (ConfigQuery.showVersion(cliOptions)) IO {
|
||||
println(s"Thorp v${thorp.BuildInfo.version}")
|
||||
ExitCode.Success
|
||||
} else
|
||||
for {
|
||||
storageService <- defaultStorageService
|
||||
actions <- Synchronise(storageService, defaultHashService, cliOptions).valueOrF(handleErrors)
|
||||
|
|
|
@ -10,6 +10,9 @@ sealed trait ConfigOption {
|
|||
}
|
||||
|
||||
object ConfigOption {
|
||||
case object Version extends ConfigOption {
|
||||
override def update(config: Config): Config = config
|
||||
}
|
||||
case class Source(path: Path) extends ConfigOption {
|
||||
override def update(config: Config): Config = config.copy(source = path.toFile)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,12 @@ package net.kemitix.thorp.core
|
|||
|
||||
trait ConfigQuery {
|
||||
|
||||
def showVersion(configOptions: Seq[ConfigOption]): Boolean =
|
||||
configOptions.exists {
|
||||
case ConfigOption.Version => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def ignoreUserOptions(configOptions: Seq[ConfigOption]): Boolean =
|
||||
configOptions.exists {
|
||||
case ConfigOption.IgnoreUserOptions => true
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.3.2")
|
||||
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.2.6")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
|
Loading…
Reference in a new issue