File tree Expand file tree Collapse file tree 3 files changed +26
-9
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 +26
-9
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import sun.misc.{Signal, SignalHandler}
44
55import java .io .{ByteArrayOutputStream , File , PrintStream }
66import java .nio .charset .StandardCharsets
7+ import java .nio .file .Paths
78import java .util .Locale
89
910import 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
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ import caseapp.core.complete.{Bash, Zsh}
55
66import java .io .File
77import java .nio .charset .Charset
8+ import java .nio .file .Paths
89import java .util
910
1011import scala .build .Logger
11- import scala .cli .CurrentParams
1212import scala .cli .commands .ScalaCommand
1313import scala .cli .internal .{Argv0 , ProfileFileUpdater }
14+ import scala .cli .{CurrentParams , ScalaCli }
1415
1516object 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 ] =
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 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" ) } {
You can’t perform that action at this time.
0 commit comments