Skip to content

Commit

Permalink
Merge branch 'main' into update-introduction-section-in-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
eloots authored Jul 10, 2023
2 parents 763764f + fd88865 commit 6f9e6b8
Show file tree
Hide file tree
Showing 32 changed files with 252 additions and 234 deletions.
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ lazy val `course-management-tools` =
.settings(commonSettings: _*)
.settings(publish / skip := true)

lazy val core = project.in(file("core")).settings(commonSettings: _*)
lazy val core = project.in(file("core"))
.settings(commonSettings: _*)
.settings(libraryDependencies ++= Dependencies.coreDependencies)

lazy val cmta = project
.in(file("cmta"))
Expand All @@ -28,8 +30,9 @@ lazy val cmtc = project
.settings(buildInfoKeys := buildKeysWithName("Course Management Tools (Client)"))

lazy val `functional-tests` = project.in(file("functional-tests"))
.dependsOn(cmta, cmtc)
.dependsOn(cmta, cmtc, core)
.settings(commonSettings: _*)
.settings(libraryDependencies ++= Dependencies.functionalTestDependencies)
.settings(publish / skip := true)

lazy val docs = project
Expand Down
15 changes: 0 additions & 15 deletions cmtc/src/main/scala/com/lunatech/cmt/client/Domain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,15 @@ package com.lunatech.cmt.client
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import sbt.io.syntax.{File, file}

object Domain:
final case class ExerciseId(value: String)
object ExerciseId:
val default: ExerciseId = ExerciseId("")

final case class StudentifiedRepo(value: File)
final case class ForceMoveToExercise(forceMove: Boolean)
object StudentifiedRepo:
val default: StudentifiedRepo = StudentifiedRepo(file(".").getAbsoluteFile.getParentFile)

final case class TemplatePath(value: String)
object TemplatePath:
val default: TemplatePath = TemplatePath("")

sealed trait InstallationSource
object InstallationSource:
final case class LocalDirectory(value: File) extends InstallationSource
final case class ZipFile(value: File) extends InstallationSource
final case class GithubProject(organisation: String, project: String) extends InstallationSource {
val displayName = s"$organisation/$project"
}
end InstallationSource

end Domain
49 changes: 0 additions & 49 deletions cmtc/src/main/scala/com/lunatech/cmt/client/Helpers.scala

This file was deleted.

77 changes: 1 addition & 76 deletions cmtc/src/main/scala/com/lunatech/cmt/client/cli/ArgParsers.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
package com.lunatech.cmt.client.cli

import caseapp.core.Error
import caseapp.core.Error.Other
import caseapp.core.argparser.{ArgParser, FlagArgParser, SimpleArgParser}
import com.lunatech.cmt.client.Domain.{
ExerciseId,
ForceMoveToExercise,
InstallationSource,
StudentifiedRepo,
TemplatePath
}
import sbt.io.syntax.{File, file}
import cats.syntax.apply.*
import com.lunatech.cmt.client.Domain.{ExerciseId, ForceMoveToExercise, TemplatePath}
import cats.syntax.either.*
import com.lunatech.cmt.client.Domain.InstallationSource.{GithubProject, LocalDirectory, ZipFile}
import com.lunatech.cmt.core.validation.FileValidations.*

object ArgParsers {

private val fileArgParser: ArgParser[File] =
SimpleArgParser.from[File]("file")(file(_).asRight)

given studentifiedRepoArgParser: ArgParser[StudentifiedRepo] =
fileArgParser.xmapError[StudentifiedRepo](
_.value,
file =>
(file.validateExists, file.validateIsDirectory)
.mapN((_, _) => StudentifiedRepo(file))
.leftMap(_.flatten)
.toEither)

given forceMoveToExerciseArgParser: ArgParser[ForceMoveToExercise] =
FlagArgParser.boolean.xmap[ForceMoveToExercise](_.forceMove, ForceMoveToExercise(_))

Expand All @@ -38,55 +14,4 @@ object ArgParsers {

given templatePathArgParser: ArgParser[TemplatePath] =
SimpleArgParser.from[TemplatePath]("template path")(TemplatePath(_).asRight)

given installationSourceArgParser: ArgParser[InstallationSource] = {

val githubProjectRegex = "([A-Za-z0-9-_]*)\\/([A-Za-z0-9-_]*)".r

def toString(installationSource: InstallationSource): String =
installationSource match {
case LocalDirectory(value) => value.getAbsolutePath()
case ZipFile(value) => value.getAbsolutePath()
case GithubProject(organisation, project) => s"$organisation/$project"
}

def fromString(str: String): Either[Error, InstallationSource] = {
val maybeFile = file(str)
val maybeGithub = str match {
case githubProjectRegex(organisation, project) => Some(GithubProject(organisation, project))
case _ => None
}

// is it a file? does it exist?
// yes
// - is it a directory?
// yes
// - it's a LocalDirectory
// no
// - does it end in '.zip'?
// yes
// - it's a ZipFile
// no
// - error - can't install from a file
// no
// - is it of the form a/b
// yes
// - it's a GithubProject
// no
// - error - i don't know what to do
(maybeFile.exists(), maybeFile.isDirectory, str.endsWith(".zip"), maybeGithub) match {
case (true, true, _, _) => LocalDirectory(maybeFile).asRight
case (true, false, true, _) => ZipFile(maybeFile).asRight
case (true, false, false, _) =>
Other(
s"'$str' is a file but not a zip file - i'm afraid I don't know how to install a course from this file").asLeft
case (false, _, _, Some(githubProject)) => githubProject.asRight
case (_, _, _, _) =>
Other(
s"'$str' is not a local directory or zip file and it doesn't appear to be a Github project either. I'm afraid I don't know how to deal with this.").asLeft
}
}

SimpleArgParser.string.xmapError[InstallationSource](toString, fromString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ import com.lunatech.cmt.{
toExecuteCommandErrorMessage
}
import com.lunatech.cmt.Helpers.{exerciseFileHasBeenModified, getFilesToCopyAndDelete, pullTestCode}
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.{ExerciseId, ForceMoveToExercise, StudentifiedRepo}
import com.lunatech.cmt.client.command.getCurrentExerciseId
import com.lunatech.cmt.client.Domain.{ExerciseId, ForceMoveToExercise}
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.syntax.*
import com.lunatech.cmt.client.cli.ArgParsers.{
exerciseIdArgParser,
forceMoveToExerciseArgParser,
studentifiedRepoArgParser
}
import com.lunatech.cmt.client.cli.ArgParsers.{exerciseIdArgParser, forceMoveToExerciseArgParser}
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.cli.enforceTrailingArgumentCount
import com.lunatech.cmt.core.command.Package.getCurrentExerciseId

object GotoExercise:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.lunatech.cmt.client.command
import caseapp.{AppName, CommandName, ExtraName, HelpMessage, RemainingArgs}
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.{CMTcConfig, CmtError, printResult}
import com.lunatech.cmt.client.Domain.{ExerciseId, ForceMoveToExercise, StudentifiedRepo}
import com.lunatech.cmt.client.Domain.{ExerciseId, ForceMoveToExercise}
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.core.validation.Validatable
import com.lunatech.cmt.client.cli.ArgParsers.{forceMoveToExerciseArgParser, studentifiedRepoArgParser}
import com.lunatech.cmt.client.cli.ArgParsers.forceMoveToExerciseArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.lunatech.cmt.client.command

import caseapp.{AppName, CommandName, ExtraName, HelpMessage, RemainingArgs}
import com.lunatech.cmt.client.{Configuration, listExercises}
import com.lunatech.cmt.client.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.{CMTcConfig, CmtError, printResult}
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.validation.Validatable
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments
import com.lunatech.cmt.client.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.Helpers.listExercises

object ListExercises:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.lunatech.cmt.client.command

import caseapp.{AppName, CommandName, ExtraName, HelpMessage, RemainingArgs}
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.StudentifiedRepo
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.{CMTcConfig, CmtError, printResult, toConsoleGreen, toConsoleYellow}
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.IO as sbtio
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments
import com.lunatech.cmt.client.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser

object ListSavedStates:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import com.lunatech.cmt.{
toExecuteCommandErrorMessage
}
import com.lunatech.cmt.Helpers.{exerciseFileHasBeenModified, getFilesToCopyAndDelete, pullTestCode}
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.{ForceMoveToExercise, StudentifiedRepo}
import com.lunatech.cmt.client.command.getCurrentExerciseId
import com.lunatech.cmt.client.Domain.ForceMoveToExercise
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.syntax.*
import com.lunatech.cmt.client.cli.ArgParsers.{forceMoveToExerciseArgParser, studentifiedRepoArgParser}
import com.lunatech.cmt.client.cli.ArgParsers.forceMoveToExerciseArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments
import com.lunatech.cmt.core.command.Package.getCurrentExerciseId

object NextExercise:

Expand All @@ -39,7 +41,6 @@ object NextExercise:

extension (options: NextExercise.Options)
def execute(configuration: Configuration): Either[CmtError, String] = {
import com.lunatech.cmt.client.Domain.ForceMoveToExercise
val cMTcConfig = new CMTcConfig(options.studentifiedRepo.getOrElse(configuration.currentCourse.value).value)

val currentExerciseId = getCurrentExerciseId(cMTcConfig.bookmarkFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.lunatech.cmt.{CMTcConfig, Helpers}
import com.lunatech.cmt.Helpers.writeStudentifiedCMTBookmark
import sbt.io.syntax.*
import sbt.io.IO as sbtio
import java.nio.charset.StandardCharsets

final case class ExerciseFiles(filesAbsolute: Seq[File], filesRelative: Seq[File])
private final case class PathARO(absolutePath: File, maybeRelativePath: Option[File])
Expand Down Expand Up @@ -34,9 +33,6 @@ def deleteCurrentState(studentifiedRepo: File)(config: CMTcConfig): Unit =
val ExerciseFiles(filesToBeDeleted, _) = getCurrentExerciseStateExceptDontTouch(studentifiedRepo)(config)
sbtio.deleteFilesEmptyDirs(filesToBeDeleted)

def getCurrentExerciseId(bookmarkFile: File): String =
sbtio.readLines(bookmarkFile, StandardCharsets.UTF_8).head

def copyTestCodeAndReadMeFiles(solution: File, prevOrNextExercise: String)(config: CMTcConfig): Unit =

val (pathsToCopy, _) =
Expand All @@ -61,6 +57,3 @@ def copyTestCodeAndReadMeFiles(solution: File, prevOrNextExercise: String)(confi
} sbtio.copyFile(solution / file, config.activeExerciseFolder / file)

writeStudentifiedCMTBookmark(config.bookmarkFile, prevOrNextExercise)

def starCurrentExercise(currentExercise: String, exercise: String): String =
if (currentExercise == exercise) " * " else " "
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import com.lunatech.cmt.{
}
import com.lunatech.cmt.Helpers.{exerciseFileHasBeenModified, getFilesToCopyAndDelete, pullTestCode}
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.{ForceMoveToExercise, StudentifiedRepo}
import com.lunatech.cmt.client.command.getCurrentExerciseId
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Domain.ForceMoveToExercise
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.syntax.*
import com.lunatech.cmt.client.cli.ArgParsers.{forceMoveToExerciseArgParser, studentifiedRepoArgParser}
import com.lunatech.cmt.client.cli.ArgParsers.forceMoveToExerciseArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments
import com.lunatech.cmt.core.command.Package.getCurrentExerciseId

object PreviousExercise:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import caseapp.{AppName, CommandName, ExtraName, HelpMessage, RemainingArgs}
import com.lunatech.cmt.{CMTcConfig, CmtError, printResult, toConsoleGreen, toConsoleYellow}
import com.lunatech.cmt.Helpers.{adaptToNixSeparatorChar, exerciseFileHasBeenModified, withZipFile}
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.StudentifiedRepo
import com.lunatech.cmt.client.command.getCurrentExerciseId
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.IO as sbtio
import sbt.io.syntax.*
import com.lunatech.cmt.core.cli.enforceNoTrailingArguments
import com.lunatech.cmt.client.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.core.command.Package.getCurrentExerciseId

object PullSolution:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import com.lunatech.cmt.{
}
import com.lunatech.cmt.Helpers.withZipFile
import com.lunatech.cmt.client.Configuration
import com.lunatech.cmt.client.Domain.{StudentifiedRepo, TemplatePath}
import com.lunatech.cmt.client.command.getCurrentExerciseId
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Domain.TemplatePath
import com.lunatech.cmt.core.validation.Validatable
import sbt.io.CopyOptions
import sbt.io.IO as sbtio
import sbt.io.syntax.*
import com.lunatech.cmt.client.cli.ArgParsers.{templatePathArgParser, studentifiedRepoArgParser}
import com.lunatech.cmt.client.cli.ArgParsers.templatePathArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.cli.CmtcCommand
import com.lunatech.cmt.core.cli.enforceTrailingArgumentCount
import com.lunatech.cmt.core.command.Package.getCurrentExerciseId

object PullTemplate:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.lunatech.cmt.client.command

import com.lunatech.cmt.client.Domain.{ExerciseId, StudentifiedRepo}
import com.lunatech.cmt.Domain.StudentifiedRepo
import com.lunatech.cmt.client.Domain.ExerciseId
import caseapp.{AppName, CommandName, ExtraName, HelpMessage, RemainingArgs}
import com.lunatech.cmt.client.cli.ArgParsers.{exerciseIdArgParser, studentifiedRepoArgParser}
import com.lunatech.cmt.client.cli.ArgParsers.exerciseIdArgParser
import com.lunatech.cmt.core.cli.ArgParsers.studentifiedRepoArgParser
import com.lunatech.cmt.client.command.deleteCurrentState
import com.lunatech.cmt.core.validation.Validatable
import com.lunatech.cmt.*
Expand Down
Loading

0 comments on commit 6f9e6b8

Please sign in to comment.