Skip to content

Commit

Permalink
Remove suffix .aux from progName when installed by cs
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Dec 28, 2022
1 parent 1234a52 commit 7fbaf4c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 9 additions & 1 deletion modules/cli/src/main/scala/scala/cli/ScalaCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ object ScalaCli {
// the Scala CLI native image, no need to manually load it.
coursier.jniutils.LoadWindowsLibrary.assumeInitialized()

val progName = (new Argv0).get("scala-cli")
val progName = {
val argv0 = (new Argv0).get("scala-cli")
val idx = argv0.lastIndexOf(File.separator)
val last = if (idx < 0) argv0 else argv0.drop(idx + 1)
last match {
case s".${name}.aux" => name // cs install binaries under .app-name.aux and to the PATH
case _ => argv0
}
}

private def checkName(name: String) = {
val baseProgName = if (Properties.isWin) progName.stripSuffix(".exe") else progName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import java.nio.charset.Charset
import java.util

import scala.build.Logger
import scala.cli.CurrentParams
import scala.cli.commands.ScalaCommand
import scala.cli.internal.{Argv0, ProfileFileUpdater}
import scala.cli.{CurrentParams, ScalaCli}

object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
override def names = List(
Expand Down Expand Up @@ -101,13 +101,11 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {

def getName(name: Option[String]): String =
name.getOrElse {
val baseName = (new Argv0).get(baseRunnerName)
val baseName = ScalaCli.progName
val idx = baseName.lastIndexOf(File.separator)
val last = if (idx < 0) baseName else baseName.drop(idx + 1)
last match {
case s".${name}.aux" => name // // cs install binaries under .app-name.aux
case name => name
}
if (idx < 0)
baseName
else baseName.drop(idx + 1)
}

def getFormat(format: Option[String]): Option[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ class SipScalaTests extends ScalaCliSuite {
}
}

if (TestUtil.isNativeCli)
test(s"usage instruction should point to scala when installing by cs") { // https://github.com/VirtusLab/scala-cli/issues/1662
TestInputs.empty.fromRoot {
root => // cs install binaries under .app-name.aux and scala-cli should drop .aux from progName
val binary = "scala".prepareBinary(root)
val csBinaryName = root / ".scala.aux"
os.move(binary, csBinaryName)
val output = os.proc(csBinaryName, "test", "--usage").call(check = false).out.text()
val usageMsg = TestUtil.removeAnsiColors(output)
expect(usageMsg.contains(" scala "))
}
}

def testHelpOutput(binaryName: String): Unit = TestInputs.empty.fromRoot { root =>
val binary = binaryName.prepareBinary(root)
for { helpOption <- Seq("help", "-help", "--help") } {
Expand Down

0 comments on commit 7fbaf4c

Please sign in to comment.