Skip to content

Commit

Permalink
Add version subcommand to cmtc (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
eloots authored Jul 28, 2023
1 parent 4f165ba commit 911795f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmtc/src/main/scala/com/lunatech/cmt/client/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import com.lunatech.cmt.client.command.{
PullTemplate,
RestoreState,
SaveState,
SetCurrentCourse
SetCurrentCourse,
Version
}

object Main extends CommandsEntryPoint:
Expand All @@ -44,4 +45,5 @@ object Main extends CommandsEntryPoint:
PullTemplate.command,
RestoreState.command,
SaveState.command,
SetCurrentCourse.command)
SetCurrentCourse.command,
Version.command)
28 changes: 28 additions & 0 deletions cmtc/src/main/scala/com/lunatech/cmt/client/command/Version.scala
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 911795f

Please sign in to comment.