Skip to content

Commit

Permalink
Allow to get the scala-cli command too
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed May 4, 2023
1 parent 3ba7816 commit 103bb11
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/coursier/getcs/GetCs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ object GetCs {
.getOrElse(fromPath("cs"))
}

/** Provides the command to run "scala-cli". Can be either a path, or a command name.
*/
def scalaCli(version: String = defaultScalaCliVersion): String =
scalaCliUrl(arch, version, Properties.isWin, Properties.isMac, Properties.isLinux)
.map(download)
.getOrElse(fromPath("scala-cli"))

private def arch: String =
sys.props.getOrElse("os.arch", "").toLowerCase(Locale.ROOT)

Expand Down Expand Up @@ -86,6 +93,8 @@ object GetCs {
def defaultVersion: String = "2.1.2"
def defaultArmVersion: String = defaultVersion

def defaultScalaCliVersion = "1.0.0-RC1"

def url(
arch: String,
version: String,
Expand Down Expand Up @@ -126,4 +135,40 @@ object GetCs {
case _ =>
None
}

def scalaCliUrl(
arch: String,
version: String,
isWin: Boolean,
isMac: Boolean,
isLinux: Boolean
): Option[String] =
arch match {
case "x86_64" | "amd64" =>
if (isWin)
Some(
s"https://github.com/VirtusLab/scala-cli/releases/download/v$version/scala-cli-x86_64-pc-win32.zip"
)
else if (isMac)
Some(
s"https://github.com/VirtusLab/scala-cli/releases/download/v$version/scala-cli-x86_64-apple-darwin.gz"
)
else if (isLinux)
Some(
s"https://github.com/VirtusLab/scala-cli/releases/download/v$version/scala-cli-x86_64-pc-linux.gz"
)
else None
case "aarch64" =>
if (isLinux)
Some(
s"https://github.com/VirtusLab/scala-cli/releases/download/v$version/scala-cli-aarch64-pc-linux.gz"
)
else if (isMac)
Some(
s"https://github.com/VirtusLab/scala-cli/releases/download/v$version/scala-cli-aarch64-apple-darwin.gz"
)
else None
case _ =>
None
}
}
14 changes: 13 additions & 1 deletion test/src/coursier/getcs/GetCsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ class GetCsTests extends munit.FunSuite {
import GetCsTests._

for (entry <- entries)
test(s"${entry.name} check") {
test(s"${entry.name} cs check") {
val url = entry.url.getOrElse {
sys.error("no URL")
}
val cache = coursier.cache.FileCache()
cache.file(coursier.util.Artifact(url)).run.unsafeRun()(cache.ec) match {
case Left(err) => throw new Exception(err)
case Right(_) =>
}
}

for (entry <- entries)
test(s"${entry.name} scala-cli check") {
val url = entry.url.getOrElse {
sys.error("no URL")
}
Expand Down

0 comments on commit 103bb11

Please sign in to comment.