Skip to content

Commit e4bebd8

Browse files
committed
Default to amd64 if arch can't be determined
1 parent 5cd8512 commit e4bebd8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/main/kotlin/com/coder/gateway/sdk/CoderCLIDownloader.kt

+6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import java.net.URL
55
import java.nio.file.Files
66
import java.nio.file.Path
77
import java.nio.file.StandardCopyOption
8+
import java.util.logging.Logger
89

910
class CoderCLIDownloader {
1011

1112
fun downloadCLI(url: URL, outputName: String, ext: String): Path {
1213
val tempPath: Path = Files.createTempFile(outputName, ext)
14+
logger.info("Downloading $url to $tempPath")
1315
url.openStream().use {
1416
Files.copy(it as InputStream, tempPath, StandardCopyOption.REPLACE_EXISTING)
1517
}
1618
return tempPath
1719
}
20+
21+
companion object {
22+
val logger = Logger.getLogger(CoderCLIDownloader::class.java.simpleName)
23+
}
1824
}

src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,45 @@ package com.coder.gateway.sdk
22

33
import java.net.URL
44
import java.nio.file.Path
5+
import java.util.logging.Logger
56

67
class CoderCLIManager(private val url: URL) {
78
private val coderCLIDownloader = CoderCLIDownloader()
89

910
fun download(): Path? {
1011
val os = getOS()
1112
val cliName = getCoderCLIForOS(os, getArch()) ?: return null
13+
logger.info("Resolved OS: $os with arch: ${getArch()}")
1214
val cliNameWitExt = if (os == OS.WINDOWS) "$cliName.exe" else cliName
1315
return coderCLIDownloader.downloadCLI(URL(url.protocol, url.host, url.port, "/bin/$cliNameWitExt"), cliName, if (os == OS.WINDOWS) ".exe" else "")
1416
}
1517

1618
fun getCoderCLIForOS(os: OS?, arch: Arch?): String? {
17-
if (os == null || arch == null) {
19+
logger.info("Resolving coder cli for $os $arch")
20+
if (os == null) {
1821
return null
1922
}
2023
return when (os) {
2124
OS.WINDOWS -> when (arch) {
2225
Arch.amd64 -> "coder-windows-amd64"
2326
Arch.arm64 -> "coder-windows-arm64"
24-
else -> null
27+
else -> "coder-windows-amd64"
2528
}
2629
OS.LINUX -> when (arch) {
2730
Arch.amd64 -> "coder-linux-amd64"
2831
Arch.arm64 -> "coder-linux-arm64"
2932
Arch.armv7 -> "coder-linux-armv7"
33+
else -> "coder-linux-amd64"
3034
}
3135
OS.MAC -> when (arch) {
3236
Arch.amd64 -> "coder-darwin-amd64"
3337
Arch.arm64 -> "coder-darwin-arm64"
34-
else -> null
38+
else -> "coder-darwin-amd64"
3539
}
3640
}
3741
}
42+
43+
companion object {
44+
val logger = Logger.getLogger(CoderCLIManager::class.java.simpleName)
45+
}
3846
}

0 commit comments

Comments
 (0)