Skip to content

Commit 7734ec3

Browse files
authored
Suggest user to update scala-cli by package manager in doctor (#1069)
* Suggest user to update scala-cli by package manager in doctor
1 parent b190866 commit 7734ec3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

modules/cli/src/main/scala/scala/cli/commands/Doctor.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ object Doctor extends ScalaCommand[DoctorOptions] {
6767
println(
6868
s"scala-cli would not be able to update itself since it is installed in multiple directories: ${scalaCliPaths.mkString(", ")}."
6969
)
70+
else if (Update.isScalaCLIInstalledByInstallationScript())
71+
println(
72+
s"scala-cli could update itself since it is correctly installed in only one location: ${scalaCliPaths.mkString}."
73+
)
7074
else
7175
println(
72-
s"scala-cli could update itself since it is correctly installed in only one location: $scalaCliPaths."
76+
s"scala-cli can be updated by your package manager since it is correctly installed in only one location: ${scalaCliPaths.mkString}."
7377
)
78+
7479
}
7580

7681
private def checkNativeDependencies(): Unit = {

modules/cli/src/main/scala/scala/cli/commands/Update.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,20 @@ object Update extends ScalaCommand[UpdateOptions] {
156156
}
157157

158158
def checkUpdateSafe(logger: Logger): Unit =
159-
try {
160-
val classesDir =
161-
getClass.getProtectionDomain.getCodeSource.getLocation.toURI.toString
162-
val binRepoDir = build.Directories.default().binRepoDir.toString()
159+
try
163160
// log about update only if scala-cli was installed from installation script
164-
if (classesDir.contains(binRepoDir))
161+
if (isScalaCLIInstalledByInstallationScript())
165162
checkUpdate(UpdateOptions(isInternalRun = true))
166-
}
167163
catch {
168164
case NonFatal(ex) =>
169165
logger.debug(s"Ignoring error during checking update: $ex")
170166
}
167+
168+
def isScalaCLIInstalledByInstallationScript(): Boolean = {
169+
val classesDir =
170+
getClass.getProtectionDomain.getCodeSource.getLocation.toURI.toString
171+
val binRepoDir = build.Directories.default().binRepoDir.toString()
172+
173+
classesDir.contains(binRepoDir)
174+
}
171175
}

0 commit comments

Comments
 (0)