Skip to content

Commit

Permalink
Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
eloots committed Jul 19, 2023
1 parent 8ca3b42 commit f067e19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.lunatech.cmt.CmtError
import java.io.File
import com.lunatech.cmt.toExecuteCommandErrorMessage

def validateTargetFolder(mainRepository: File, target: File): Either[CmtError, Unit] =
val canonicalStudentifyBaseDirectory = target.getCanonicalPath
def validateDestinationFolder(mainRepository: File, destination: File): Either[CmtError, Unit] =
val canonicalTarget = destination.getCanonicalPath
val canonicalMainRepository = mainRepository.getCanonicalPath
val mainRepositoryEqualsStudentifyBaseDirectory = canonicalStudentifyBaseDirectory == canonicalMainRepository
val StudentifyBaseDirectoryIsSubfolderOfmainRepository =
canonicalStudentifyBaseDirectory.startsWith(canonicalMainRepository)
(mainRepositoryEqualsStudentifyBaseDirectory, StudentifyBaseDirectoryIsSubfolderOfmainRepository) match {
val destinationEqualsMainRepository = canonicalTarget == canonicalMainRepository
val destinationIsSubfolderOfmainRepository =
canonicalTarget.startsWith(canonicalMainRepository)
(destinationEqualsMainRepository, destinationIsSubfolderOfmainRepository) match {
case (true, _) =>
Left("destination folder cannot be the same as the main repository root folder".toExecuteCommandErrorMessage)
case (_, true) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.lunatech.cmt.{CMTaConfig, CmtError, printResult, toConsoleGreen}
import com.lunatech.cmt.admin.Domain.{ForceDeleteDestinationDirectory, LinearizeBaseDirectory, MainRepository}
import com.lunatech.cmt.admin.cli.ArgParsers.{forceDeleteDestinationDirectoryArgParser, linearizeBaseDirectoryArgParser}
import com.lunatech.cmt.admin.cli.SharedOptions
import com.lunatech.cmt.admin.validateTargetFolder
import com.lunatech.cmt.admin.validateDestinationFolder
import com.lunatech.cmt.core.cli.CmtCommand
import com.lunatech.cmt.core.execution.Executable
import com.lunatech.cmt.core.validation.Validatable
Expand All @@ -33,7 +33,9 @@ object Linearize:
def validated(): Either[CmtError, Linearize.Options] =
for {
mainRepository <- resolveMainRepoPath(options.shared.mainRepository.value)
_ <- validateTargetFolder(mainRepository, options.linearizeBaseDirectory.value)
_ <- validateDestinationFolder(
mainRepository = mainRepository,
destination = options.linearizeBaseDirectory.value)
} yield options
end given

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.lunatech.cmt.core.execution.Executable
import com.lunatech.cmt.{CMTaConfig, CmtError, printResult, toConsoleGreen}
import sbt.io.IO as sbtio
import sbt.io.syntax.*
import com.lunatech.cmt.admin.validateTargetFolder
import com.lunatech.cmt.admin.validateDestinationFolder
import com.lunatech.cmt.admin.cli.SharedOptions
import com.lunatech.cmt.core.validation.Validatable
import com.lunatech.cmt.admin.cli.ArgParsers.{
Expand Down Expand Up @@ -47,7 +47,9 @@ object Studentify:
def validated(): Either[CmtError, Studentify.Options] =
for {
mainRepository <- resolveMainRepoPath(options.shared.mainRepository.value)
_ <- validateTargetFolder(mainRepository, options.studentifyBaseDirectory.value)
_ <- validateDestinationFolder(
mainRepository = mainRepository,
destination = options.studentifyBaseDirectory.value)
} yield options
end validated
end given
Expand Down

0 comments on commit f067e19

Please sign in to comment.