From 911795f5aefedb79a6d289c6a769dc0fff54e5ad Mon Sep 17 00:00:00 2001 From: Eric Loots Date: Fri, 28 Jul 2023 17:48:45 +0200 Subject: [PATCH] Add version subcommand to cmtc (#270) --- .../scala/com/lunatech/cmt/client/Main.scala | 6 ++-- .../lunatech/cmt/client/command/Version.scala | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 cmtc/src/main/scala/com/lunatech/cmt/client/command/Version.scala diff --git a/cmtc/src/main/scala/com/lunatech/cmt/client/Main.scala b/cmtc/src/main/scala/com/lunatech/cmt/client/Main.scala index 31b36e7a..44f62b7a 100644 --- a/cmtc/src/main/scala/com/lunatech/cmt/client/Main.scala +++ b/cmtc/src/main/scala/com/lunatech/cmt/client/Main.scala @@ -26,7 +26,8 @@ import com.lunatech.cmt.client.command.{ PullTemplate, RestoreState, SaveState, - SetCurrentCourse + SetCurrentCourse, + Version } object Main extends CommandsEntryPoint: @@ -44,4 +45,5 @@ object Main extends CommandsEntryPoint: PullTemplate.command, RestoreState.command, SaveState.command, - SetCurrentCourse.command) + SetCurrentCourse.command, + Version.command) diff --git a/cmtc/src/main/scala/com/lunatech/cmt/client/command/Version.scala b/cmtc/src/main/scala/com/lunatech/cmt/client/command/Version.scala new file mode 100644 index 00000000..99e82cdf --- /dev/null +++ b/cmtc/src/main/scala/com/lunatech/cmt/client/command/Version.scala @@ -0,0 +1,28 @@ +package com.lunatech.cmt.client.command + +import caseapp.{AppName, CommandName, HelpMessage, RemainingArgs} +import com.lunatech.cmt.CmtError +import com.lunatech.cmt.core.cli.CmtCommand +import com.lunatech.cmt.core.execution.Executable +import com.lunatech.cmt.core.validation.Validatable +import com.lunatech.cmt.printResult +import com.lunatech.cmt.version.BuildInfo +object Version: + @AppName("version") + @CommandName("version") + @HelpMessage("Print version info") + final case class Options() + + given Validatable[Version.Options] with + extension (options: Version.Options) def validated(): Either[CmtError, Version.Options] = Right(options) + end given + + given Executable[Version.Options] with + extension (options: Version.Options) def execute(): Either[CmtError, String] = Right(BuildInfo.toString) + end given + + val command: CmtCommand[Version.Options] = new CmtCommand[Version.Options] { + + def run(options: Version.Options, args: RemainingArgs): Unit = + options.validated().flatMap(_.execute()).printResult() + }