File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed
cli/src/main/scala/scala/cli
commands/installcompletions
integration/src/test/scala/scala/cli/integration Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,15 @@ object ScalaCli {
2121 // the Scala CLI native image, no need to manually load it.
2222 coursier.jniutils.LoadWindowsLibrary .assumeInitialized()
2323
24- val progName = (new Argv0 ).get(" scala-cli" )
24+ val progName = {
25+ val argv0 = (new Argv0 ).get(" scala-cli" )
26+ val idx = argv0.lastIndexOf(File .separator)
27+ val last = if (idx < 0 ) argv0 else argv0.drop(idx + 1 )
28+ last match {
29+ case s " . ${name}.aux " => name // cs install binaries under .app-name.aux and 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
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ import java.nio.charset.Charset
88import java .util
99
1010import scala .build .Logger
11- import scala .cli .CurrentParams
1211import scala .cli .commands .ScalaCommand
1312import scala .cli .internal .{Argv0 , ProfileFileUpdater }
13+ import scala .cli .{CurrentParams , ScalaCli }
1414
1515object InstallCompletions extends ScalaCommand [InstallCompletionsOptions ] {
1616 override def names = List (
@@ -101,13 +101,11 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
101101
102102 def getName (name : Option [String ]): String =
103103 name.getOrElse {
104- val baseName = ( new Argv0 ).get(baseRunnerName)
104+ val baseName = ScalaCli .progName
105105 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- }
106+ if (idx < 0 )
107+ baseName
108+ else baseName.drop(idx + 1 )
111109 }
112110
113111 def getFormat (format : Option [String ]): Option [String ] =
Original file line number Diff line number Diff 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 install 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()
118+ val usageMsg = TestUtil .removeAnsiColors(output)
119+ expect(usageMsg.contains(" scala " ))
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" ) } {
You can’t perform that action at this time.
0 commit comments