Skip to content

Commit 29845f0

Browse files
committed
Remove suffix .aux from progName when installed by cs
1 parent 1234a52 commit 29845f0

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

modules/cli/src/main/scala/scala/cli/ScalaCli.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sun.misc.{Signal, SignalHandler}
44

55
import java.io.{ByteArrayOutputStream, File, PrintStream}
66
import java.nio.charset.StandardCharsets
7+
import java.nio.file.Paths
78
import java.util.Locale
89

910
import scala.build.blooprifle.FailedToStartServerException
@@ -21,7 +22,14 @@ object ScalaCli {
2122
// the Scala CLI native image, no need to manually load it.
2223
coursier.jniutils.LoadWindowsLibrary.assumeInitialized()
2324

24-
val progName = (new Argv0).get("scala-cli")
25+
val progName = {
26+
val argv0 = (new Argv0).get("scala-cli")
27+
val last = Paths.get(argv0).getFileName.toString
28+
last match {
29+
case s".${name}.aux" => name // cs installs binaries under .app-name.aux and adds them to the PATH
30+
case _ => argv0
31+
}
32+
}
2533

2634
private def checkName(name: String) = {
2735
val baseProgName = if (Properties.isWin) progName.stripSuffix(".exe") else progName

modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import caseapp.core.complete.{Bash, Zsh}
55

66
import java.io.File
77
import java.nio.charset.Charset
8+
import java.nio.file.Paths
89
import java.util
910

1011
import scala.build.Logger
11-
import scala.cli.CurrentParams
1212
import scala.cli.commands.ScalaCommand
1313
import scala.cli.internal.{Argv0, ProfileFileUpdater}
14+
import scala.cli.{CurrentParams, ScalaCli}
1415

1516
object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
1617
override def names = List(
@@ -101,13 +102,8 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
101102

102103
def getName(name: Option[String]): String =
103104
name.getOrElse {
104-
val baseName = (new Argv0).get(baseRunnerName)
105-
val idx = baseName.lastIndexOf(File.separator)
106-
val last = if (idx < 0) baseName else baseName.drop(idx + 1)
107-
last match {
108-
case s".${name}.aux" => name // // cs install binaries under .app-name.aux
109-
case name => name
110-
}
105+
val progName = ScalaCli.progName
106+
Paths.get(progName).getFileName.toString
111107
}
112108

113109
def getFormat(format: Option[String]): Option[String] =

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ class SipScalaTests extends ScalaCliSuite {
107107
}
108108
}
109109

110+
if (TestUtil.isNativeCli)
111+
test(s"usage instruction should point to scala when installing by cs") { // https://github.com/VirtusLab/scala-cli/issues/1662
112+
TestInputs.empty.fromRoot {
113+
root => // cs installs binaries under .app-name.aux and scala-cli should drop .aux from progName
114+
val binary = "scala".prepareBinary(root)
115+
val csBinaryName = root / ".scala.aux"
116+
os.move(binary, csBinaryName)
117+
val output = os.proc(csBinaryName, "test", "--usage").call(check = false).out.text().trim
118+
val usageMsg = TestUtil.removeAnsiColors(output)
119+
expect(usageMsg == "Usage: scala test [options]")
120+
}
121+
}
122+
110123
def testHelpOutput(binaryName: String): Unit = TestInputs.empty.fromRoot { root =>
111124
val binary = binaryName.prepareBinary(root)
112125
for { helpOption <- Seq("help", "-help", "--help") } {

0 commit comments

Comments
 (0)