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() + }