Skip to content

Commit 5ea0967

Browse files
committed
impl: improve progress reporting while downloading the cli
1 parent 736325e commit 5ea0967

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ internal data class Version(
4747
@Json(name = "version") val version: String,
4848
)
4949

50-
private const val DOWNLOADING_CODER_CLI = "Downloading Coder CLI..."
5150

5251
/**
5352
* Do as much as possible to get a valid, up-to-date CLI.
@@ -67,6 +66,11 @@ suspend fun ensureCLI(
6766
buildVersion: String,
6867
showTextProgress: (String) -> Unit
6968
): CoderCLIManager {
69+
fun reportProgress(msg: String) {
70+
showTextProgress(msg)
71+
context.logger.info(msg)
72+
}
73+
7074
val settings = context.settingsStore.readOnly()
7175
val cli = CoderCLIManager(context, deploymentURL)
7276

@@ -77,14 +81,13 @@ suspend fun ensureCLI(
7781
// the 304 method.
7882
val cliMatches = cli.matchesVersion(buildVersion)
7983
if (cliMatches == true) {
80-
context.logger.info("Local CLI version matches server version: $buildVersion")
84+
reportProgress("Local CLI version matches server version: $buildVersion")
8185
return cli
8286
}
8387

8488
// If downloads are enabled download the new version.
8589
if (settings.enableDownloads) {
86-
context.logger.info(DOWNLOADING_CODER_CLI)
87-
showTextProgress(DOWNLOADING_CODER_CLI)
90+
reportProgress("Downloading Coder CLI...")
8891
try {
8992
cli.download(buildVersion, showTextProgress)
9093
return cli
@@ -102,12 +105,12 @@ suspend fun ensureCLI(
102105
val dataCLI = CoderCLIManager(context, deploymentURL, true)
103106
val dataCLIMatches = dataCLI.matchesVersion(buildVersion)
104107
if (dataCLIMatches == true) {
108+
reportProgress("Local CLI version from data directory matches server version: $buildVersion")
105109
return dataCLI
106110
}
107111

108112
if (settings.enableDownloads) {
109-
context.logger.info(DOWNLOADING_CODER_CLI)
110-
showTextProgress(DOWNLOADING_CODER_CLI)
113+
reportProgress("Downloading Coder CLI to the data directory...")
111114
dataCLI.download(buildVersion, showTextProgress)
112115
return dataCLI
113116
}

0 commit comments

Comments
 (0)