From aa71124f10287c8ad7df199537f1e0a8d67115fd Mon Sep 17 00:00:00 2001 From: Eric Loots Date: Fri, 14 Jul 2023 16:13:09 +0200 Subject: [PATCH] Update cmta/src/main/scala/com/lunatech/cmt/admin/command/New.scala Co-authored-by: Trevor Burton-McCreadie --- .../com/lunatech/cmt/admin/command/New.scala | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cmta/src/main/scala/com/lunatech/cmt/admin/command/New.scala b/cmta/src/main/scala/com/lunatech/cmt/admin/command/New.scala index 640daeb1..115cd18e 100644 --- a/cmta/src/main/scala/com/lunatech/cmt/admin/command/New.scala +++ b/cmta/src/main/scala/com/lunatech/cmt/admin/command/New.scala @@ -52,17 +52,22 @@ object New: // list the contents of the ~/Courses directory, if there's anything already matching the // name then get the count so we can append to the name and prevent conflicts template <- options.template.value - existingFilesWithSameName = sbtio.listFiles( - configuration.coursesDirectory.value, - new FileFilter { - override def accept(file: File): Boolean = - file.name.startsWith(template.project) - }) - discriminator = if (existingFilesWithSameName.size > 0) s"-${existingFilesWithSameName.size}" else "" - targetDirectoryName = s"${template.project}$discriminator" + template <- options.template.value + targetDirectoryName = createTargetDirectoryName() newRepo <- newCmtRepoFromGithubProject(template, targetDirectoryName, configuration) } yield newRepo + private def createTargetDirectoryName(): String = { + val existingFilesWithSameName = sbtio.listFiles( + configuration.coursesDirectory.value, + new FileFilter { + override def accept(file: File): Boolean = + file.name.startsWith(template.project) + }) + val discriminator = if (existingFilesWithSameName.size > 0) s"-${existingFilesWithSameName.size}" else "" + s"${template.project}$discriminator" + } + private def cloneMainRepo(githubProject: GithubProject, tmpDir: File): Either[CmtError, TagSet] = val project = githubProject.project val organisation = githubProject.organisation