11package com.coder.toolbox.cli
22
3+ import com.coder.toolbox.CoderToolboxContext
34import com.coder.toolbox.cli.ex.MissingVersionException
45import com.coder.toolbox.cli.ex.ResponseException
56import com.coder.toolbox.cli.ex.SSHConfigFormatException
6- import com.coder.toolbox.logger.CoderLoggerFactory
77import com.coder.toolbox.settings.CoderSettings
88import com.coder.toolbox.settings.CoderSettingsState
99import com.coder.toolbox.util.CoderHostnameVerifier
@@ -17,6 +17,7 @@ import com.coder.toolbox.util.getHeaders
1717import com.coder.toolbox.util.getOS
1818import com.coder.toolbox.util.safeHost
1919import com.coder.toolbox.util.sha1
20+ import com.jetbrains.toolbox.api.core.diagnostics.Logger
2021import com.squareup.moshi.Json
2122import com.squareup.moshi.JsonClass
2223import com.squareup.moshi.JsonDataException
@@ -55,12 +56,13 @@ internal data class Version(
5556 * from step 2 with the data directory.
5657 */
5758fun ensureCLI (
59+ context : CoderToolboxContext ,
5860 deploymentURL : URL ,
5961 buildVersion : String ,
6062 settings : CoderSettings ,
6163 indicator : ((t: String ) -> Unit )? = null,
6264): CoderCLIManager {
63- val cli = CoderCLIManager (deploymentURL, settings)
65+ val cli = CoderCLIManager (deploymentURL, context.logger, settings)
6466
6567 // Short-circuit if we already have the expected version. This
6668 // lets us bypass the 304 which is slower and may not be
@@ -89,7 +91,7 @@ fun ensureCLI(
8991 }
9092
9193 // Try falling back to the data directory.
92- val dataCLI = CoderCLIManager (deploymentURL, settings, true )
94+ val dataCLI = CoderCLIManager (deploymentURL, context.logger, settings, true )
9395 val dataCLIMatches = dataCLI.matchesVersion(buildVersion)
9496 if (dataCLIMatches == true ) {
9597 return dataCLI
@@ -120,14 +122,13 @@ data class Features(
120122class CoderCLIManager (
121123 // The URL of the deployment this CLI is for.
122124 private val deploymentURL : URL ,
125+ private val logger : Logger ,
123126 // Plugin configuration.
124- private val settings : CoderSettings = CoderSettings (CoderSettingsState ()),
127+ private val settings : CoderSettings = CoderSettings (CoderSettingsState (), logger ),
125128 // If the binary directory is not writable, this can be used to force the
126129 // manager to download to the data directory instead.
127130 forceDownloadToData : Boolean = false ,
128131) {
129- private val logger = CoderLoggerFactory .getLogger(javaClass)
130-
131132 val remoteBinaryURL: URL = settings.binSource(deploymentURL)
132133 val localBinaryPath: Path = settings.binPath(deploymentURL, forceDownloadToData)
133134 val coderConfigPath: Path = settings.dataDir(deploymentURL).resolve(" config" )
@@ -196,7 +197,7 @@ class CoderCLIManager(
196197 } catch (e: FileNotFoundException ) {
197198 null
198199 } catch (e: Exception ) {
199- logger.warn(" Unable to calculate hash for $localBinaryPath " , e )
200+ logger.warn(e, " Unable to calculate hash for $localBinaryPath " )
200201 null
201202 }
202203
@@ -275,7 +276,8 @@ class CoderCLIManager(
275276 if (settings.sshLogDirectory.isNotBlank()) escape(settings.sshLogDirectory) else null ,
276277 if (feats.reportWorkspaceUsage) " --usage-app=jetbrains" else null ,
277278 )
278- val backgroundProxyArgs = baseArgs + listOfNotNull(if (feats.reportWorkspaceUsage) " --usage-app=disable" else null )
279+ val backgroundProxyArgs =
280+ baseArgs + listOfNotNull(if (feats.reportWorkspaceUsage) " --usage-app=disable" else null )
279281 val extraConfig =
280282 if (settings.sshConfigOptions.isNotBlank()) {
281283 " \n " + settings.sshConfigOptions.prependIndent(" " )
@@ -417,6 +419,7 @@ class CoderCLIManager(
417419 is InvalidVersionException -> {
418420 logger.info(" Got invalid version from $localBinaryPath : ${e.message} " )
419421 }
422+
420423 else -> {
421424 // An error here most likely means the CLI does not exist or
422425 // it executed successfully but output no version which
0 commit comments